01-29-2023 09:26 PM
The below works, it outputs an empty value to the diagnostic console. However if I try to check if the siteManager field is empty, I get an error.
// Returns the current FormInstance
CustomActionForm thisForm = args.FormInstance;
// Initialize a new form modifier for changing a field.
FormModifier formModifier = thisForm.CreateUnityFormModifier();
// Return the name of the form
string formName = thisForm.FormTemplate.Name;
if (formName == "Trainee Development Review")
{
ValueField fieldValue = thisForm.AllFields.ValueFields.Find("sitemanager");
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose,
String.Format("SiteManager is empty? = {0}", fieldValue));
}
01-29-2023 11:36 PM
if (string.IsNullOrWhiteSpace(fieldValue.AlphaNumericValue) || (fieldValue.IsEmpty))
"Object reference not set as an instance of an object"
I had to add the 'AlphaNumericValue' to fieldValue, otherwise I get a 'cannot convert from ValueField to string.
Also, this works fine:
ValueField fieldValue = thisForm.AllFields.ValueFields.Find("sitemanager");
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose,
String.Format("SiteManager is empty? = {0}", fieldValue));
I get a blank entry in the diagnostic console. However if I try fieldValue.isEmpty or fieldValue.AlphaNumericValue, I get the error.
I don't know what's happening here.
01-30-2023 12:08 AM
In what context is the code being executed? Can you share what the script looks like?
01-30-2023 12:13 AM
I'm very much scratching my head at this point.
01-30-2023 09:02 AM
I agree with @George Sialmas that it sounds like your fieldValue parameter is null, and you are getting the error because you are dereferencing a property off the null object.
You can check this way if (fieldValue?.IsEmpty ?? true)
01-30-2023 12:32 AM
1. In what context is the code being executed? Workflow, Scheduler, CustomActionEvent? I'm trying to understand why you are checking fieldValue is null.
2. How were you checking if the property (fieldValue) was null? Can you tell me what you had in your IF statement? The reason I'm asking is because whenever I've wanted to check if a fieldValue is null I would use the following:
If ((fieldValue ==null) || (fieldValue.IsEmpty))
{
app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Verbose, "{0}: fieldValue {1} is empty.", SCRIPT_NAME, fieldValue);
}
and it worked for me.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.