From 7b341fe8f5695445cb10abffb049b77dd24f3bcc Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 23 Oct 2024 22:05:28 +0000 Subject: [PATCH] case 4615 --- server/AyaNova/biz/CustomFieldsValidator.cs | 25 +++++++++++++++++---- server/AyaNova/biz/PMBiz.cs | 2 +- server/AyaNova/biz/QuoteBiz.cs | 2 +- server/AyaNova/biz/WorkOrderBiz.cs | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/server/AyaNova/biz/CustomFieldsValidator.cs b/server/AyaNova/biz/CustomFieldsValidator.cs index 6fe9a8fd..7ec4f378 100644 --- a/server/AyaNova/biz/CustomFieldsValidator.cs +++ b/server/AyaNova/biz/CustomFieldsValidator.cs @@ -7,17 +7,22 @@ namespace AyaNova.Biz { internal static class CustomFieldsValidator { - internal static void Validate(BizObject biz, FormCustom formCustom, string customFields) + internal static void Validate(BizObject biz, FormCustom formCustom, string customFields, string onlyIfStartsWith = null) { bool hasCustomData = !string.IsNullOrWhiteSpace(customFields); //No form custom = no template to check against so nothing to do if (formCustom == null) return; - - var FormTemplate = JArray.Parse(formCustom.Template); + + + //case 4615 + bool checkPrefix = !string.IsNullOrEmpty(onlyIfStartsWith); + + var FormTemplate = JArray.Parse(formCustom.Template); var ThisFormCustomFieldsList = FormFieldOptionalCustomizableReference.FormFieldReferenceList(formCustom.FormKey).Where(z => z.IsCustomField == true).Select(z => z.TKey).ToList(); + //If the customFields string is empty then only validation is if any of the fields are required to be filled in if (!hasCustomData) { @@ -28,6 +33,10 @@ namespace AyaNova.Biz var fldKey = FormTemplate[i]["fld"].Value(); var fldRequired = FormTemplate[i]["required"].Value(); //Check if this is an expected custom field and that it was set to required + + //case 4615 + if (checkPrefix) + continue; if (ThisFormCustomFieldsList.Contains(fldKey) && fldRequired == true) { //Ok, this field is required but custom fields are all empty so add this error @@ -43,13 +52,21 @@ namespace AyaNova.Biz //NOTE: to save bandwidth the actual custom fields look like this: // - {c1:"blah",c2:"blah",c3:"blah".....c16:"blah"} //However the LT field names might be WidgetCustom1 or UserCustom16 so we need to translate by EndsWith - + //Top level object is a Object not an array when it comes to custom fields and the key names are the custom fields abbreviated var CustomFieldData = JObject.Parse(customFields); //make sure all the *required* keys are present foreach (string iFldKey in ThisFormCustomFieldsList) { + //case 4615 + //ensure descendant custom fields are only checked against matching descendant objects + if (checkPrefix && !iFldKey.StartsWith(onlyIfStartsWith)) + continue; + //ensure when validating work order header don't check workorder item custom fields as both could be present here + if (!checkPrefix && iFldKey.StartsWith("WorkOrderItem")) + continue; + //Translate the LT field key to the actual customFieldData field key var InternalCustomFieldName = FormFieldOptionalCustomizableReference.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey); diff --git a/server/AyaNova/biz/PMBiz.cs b/server/AyaNova/biz/PMBiz.cs index f11620a3..9ec705ba 100644 --- a/server/AyaNova/biz/PMBiz.cs +++ b/server/AyaNova/biz/PMBiz.cs @@ -1512,7 +1512,7 @@ namespace AyaNova.Biz RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors //validate custom fields - CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields); + CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields, "WorkOrderItem"); } } diff --git a/server/AyaNova/biz/QuoteBiz.cs b/server/AyaNova/biz/QuoteBiz.cs index 71849617..b3a63c9a 100644 --- a/server/AyaNova/biz/QuoteBiz.cs +++ b/server/AyaNova/biz/QuoteBiz.cs @@ -1748,7 +1748,7 @@ namespace AyaNova.Biz RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors //validate custom fields - CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields); + CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields, "WorkOrderItem"); } } diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index 592b7dab..4edcc4b5 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -2566,7 +2566,7 @@ namespace AyaNova.Biz RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors //validate custom fields - CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields); + CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields, "WorkOrderItem"); } }