logo

NJP

ATF - Custom Step Configuration3 - Validation of dropdown value using the script

Import · Oct 29, 2021 · article

ATF - Custom Step Configuration3 - Validation of dropdown value using the script

Hi,

This Step configuration takes the group name as an input and passes an active user name and sysId to output variables.

Step Environment: Server Independent

Category: Server

Input variable:

image

Description generation script:

(function generateDescription(step) { var description = "Validation of " + step.inputs.u_fieldname + " field Dropdown's on "+ step.inputs.u_tablename + " form"; return description;

})(step);

Step execution script:

(function executeStep(inputs, outputs, stepResult, timeout) {

var arr = []; var arr1 = []; var arr3 = []; var arr4 = []; var m = 0; var n = 0; var i = 0;

var j = 0;

var input = inputs.u_input_string; var tableNme = inputs.u_tablename; var fieldName = inputs.u_fieldname; var dependentValue = inputs.u_dependentvalue;

var language01 = inputs.u_language;

function getInAndOut() {

arr = input.split(','); var rec = new GlideRecord('sys_choice'); rec.addQuery('inactive', false); rec.addQuery('name', tableNme); rec.addQuery('element', fieldName); rec.addQuery('language', language01); rec.addQuery('dependent_value', dependentValue); rec.query(); while (rec.next()) { (arr1.push(rec.label.getDisplayValue())); } gs.print("Input : " + arr); gs.print("OutPut : " + arr1); i = (arr.length).toString();

j = (arr1.length).toString();

}

function VryInptWithOutput() { for (k = 0; k < i; k++) { for (l = 0; l < j; l++) { if (arr[k] == arr1[l]) { m++; break; } if (l == j - 1) { if (arr[k] !== arr1[l]) { (arr3.push(arr[k])); } } } }

}

function VryOutputWithInpt() { for (q = 0; q < j; q++) { for (r = 0; r < i; r++) { if (arr1[q] == arr[r]) { n++; break; } if (r == (i - 1)) { if (arr1[q] !== arr[r]) { (arr4.push(arr1[q])); } } } }

}

function pass() { stepResult.setOutputMessage(MESSAGE_KEY_PASS); stepResult.setSuccess();

}

function fail() {

var arr5 = []; if (m < i) { stepResult.setOutputMessage(MESSAGE_KEY_FAILED_All_Not_Found); (arr5.push(MESSAGE_KEY_FAILED_All_Not_Found)); } if (j > n) { stepResult.setOutputMessage(MESSAGE_KEY_FAILED_Additional_Found); (arr5.push(MESSAGE_KEY_FAILED_Additional_Found)); } stepResult.setOutputMessage(arr5); stepResult.setFailed();

}

getInAndOut(); VryInptWithOutput();

VryOutputWithInpt();

var MESSAGE_KEY_PASS = "All records found and No additional found"; var MESSAGE_KEY_FAILED_All_Not_Found = "*********Out of " + i + " only " + m + " Record's found and records not found are [" + arr3 + "]";

var MESSAGE_KEY_FAILED_Additional_Found = "*********" + (j - n) + " Additional Record's found and the records found additinally are [" + arr4 + "]*********";

if ((m == i) && (j == n)) { pass(); } else if ((m !== i) || (j !== n)) { fail();

}

outputs.u_check = arr3[0];

Note:

Input Values should be provided separated by a Comma

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/atf-custom-step-configuration3-validation-of-dropdown-value/ta-p/2297334