The CreatorCon Call for Content is officially open! Get started here.

sushmapinapati
Tera Contributor

 

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:

find_real_file.png

 
 
 
 
 
 
(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

Comments
Jason Shone
Kilo Contributor

seems to be an error in the code:

 

Could not save record because of a compile error: JavaScript parse error at line (157) column (8) problem = missing ) in parenthetical (<refname>; line 157)

 

find_real_file.png

 

Guessing it should looks something like this:

 

}(inputs, outputs, stepResult));

 

Also getting errors on test run:

 

ERROR Test failed: Function print is not allowed in scope sn_incident_atf. Use gs.debug() or gs.info() instead

Version history
Last update:
‎10-29-2021 12:05 AM
Updated by: