Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

g_scratchpad not working for client script in Agent Workspace Incident creation form

Pratik13
Giga Contributor

Hi,

I am trying to populate sub category list in agent workspace incident creation.

find_real_file.png

On selecting the category the sub-category L1 list doesn't populate.

This is the client script:

 

function onLoad() {

//alert ("CS running now");

//Type appropriate comment here, and begin script below
var categoriesTree = g_scratchpad.atosChoices;
var renderFields = g_scratchpad.choicesFields;
var setFields = g_scratchpad.setFields;

for (var rF = 0; rF < renderFields.length; rF++) {
g_form.clearOptions(renderFields[rF]);
g_form.addOption(renderFields[rF], '', '-- None --', 0);
}

var _dependentValue = {}; // Stash for dependent values

// Process categories tree
for (var cat = 0; cat < categoriesTree.length; cat++) {
// At first add categories which don't depend on any other values
if (categoriesTree[cat].dependent == "") {
g_form.addOption(categoriesTree[cat].name, categoriesTree[cat].value, categoriesTree[cat].label);
}

// If there is already value set for field being processed then save it in the stash..
if (setFields[categoriesTree[cat].name] == categoriesTree[cat].value) {
_dependentValue[categoriesTree[cat].value] = categoriesTree[cat].value;
g_form.setValue(categoriesTree[cat].name, categoriesTree[cat].value); //..and set correct value on the form

//jslog("vals: " + categoriesTree[cat].name + " - " + categoriesTree[cat].value + " setFields: " + setFields[categoriesTree[cat].name]);
}

// If currently processed category is already set (and exists in stash) add
// options to slave list/category
if (_dependentValue[categoriesTree[cat].dependent]) {
if (categoriesTree[cat].value != setFields[categoriesTree[cat].name]) {
g_form.addOption(categoriesTree[cat].name, categoriesTree[cat].value, categoriesTree[cat].label);

// console.log("vals2: " + categoriesTree[cat].name + " - " + categoriesTree[cat].value );
}
}
}
}

 

Any help is appreciated.

10 REPLIES 10

We had a similar problem. There is currently a known issue with this: https://hi.service-now.com/kb_view.do?sysparm_article=KB0793409

Dependent fields is the work around for this at the time.