generic stopping condition to verify all mandatory form fields are completed

Tal5
Giga Guru

Hi everyone

I would like to add a stopping condition to my flow that checks whether all mandatory fields in a form have been filled in.

The challenge is that the mandatory fields different each form .

Is there a way to implement a general script or method that can dynamically check if all required fields (regardless of the specific form) have been completed, so that the flow only continues when this condition is met?

Any guidance or code examples would be appreciated.

 

1 REPLY 1

SamrudhiK
Tera Contributor

Hello @Tal5 

You can use a Script step (in a Flow or Subflow) or a Scripted Condition with this logic:

  1. Identify the table and record (sys_id).

  2. Use GlideRecord to get the record.

  3. Loop through the fields, check if:

    • The field is mandatory (mandatory=true).

    • The field is empty.

  4. If any mandatory field is empty, return false.

 

sample Script you can use in a Script step in a Flow or Subflow:

 

javascript
CopyEdit
 

(function execute(inputs, outputs) {
var tableName = inputs.table_name;
var recordId = inputs.record_sys_id;

var gr = new GlideRecord(tableName);
if (!gr.get(recordId)) {
outputs.allMandatoryFieldsFilled = false;
return;
}

var tableFields = GlideTableDescriptor.get(tableName).getFields();
var allFilled = true;

for (var i = 0; i < tableFields.size(); i++) {
var field = tableFields.get(i);
var fieldName = field.getName();

// Skip system fields and variables
if (fieldName.startsWith("sys_") || fieldName == "variables")
continue;

if (field.isMandatory()) {
var value = gr.getValue(fieldName);
if (!value) {
allFilled = false;
break;
}
}
}

outputs.allMandatoryFieldsFilled = allFilled;

})(inputs, outputs);