case 4615

This commit is contained in:
2024-10-23 22:05:28 +00:00
parent 46dc29e51c
commit 7b341fe8f5
4 changed files with 24 additions and 7 deletions

View File

@@ -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<string>();
var fldRequired = FormTemplate[i]["required"].Value<bool>();
//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);

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}