g_scratchpad not working for client script in Agent Workspace Incident creation form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2020 04:39 AM
Hi,
I am trying to populate sub category list in agent workspace incident creation.
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.
- Labels:
-
Agent Workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2020 03:05 AM
Yes, renderField value is showing undefined in agent workspace but working properly elsewhere.
I guess g_scratchpad is not able to get values.
Any alternative for this?
Any help appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2020 03:13 AM
Hi Pratik,
Use onLoad client script and then use GlideAjax and Script Include
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2020 02:23 AM
Hi, As suggested I wrote the client Script and Script Include:
Client Script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga=new GlideAjax('ScriptIncludeGlideAjax');
ga.addParam('sysparm_name','getCategoryName');
ga.addParam('sysparm_categoryName',g_form.getValue('category'));
ga.getXML(callBackFunction);
function callBackFunction(response)
{
var answer=response.responseXML.documentElement.getAttribute("answer");
var userSysIds = JSON.parse(answer);
for (var i=0; i< userSysIds.length; i++)
{
alert(userSysIds[i]);
//g_form.setValue('subcategory','answer');
}
//Type appropriate comment here, and begin script below
}
Script Include:
var GlideAjaxScriptInclude = Class.create();
GlideAjaxScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCategoryName : function()
{
var res = [];
var gr= new GlideRecord('u_ssp_categories_map');
gr.addQuery('u_incident_category',this.getParameter('sysparm_categoryName'));// tools=sysid
gr.query();
while(gr.next()){
res.push(gr.getDisplayValue('u_incident_subcategory_1'));
gs.addInfoMessage(res);
return JSON.stringify(res);
}
},
type: 'GlideAjaxScriptInclude'
});
But still the subcategory lists is not popping or even the alert box highlighted above is not working.
Any help appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2020 09:16 PM
can you put log in your display business rule ? while executing it from Agent workspace are you able to get correct result in display business rule ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 12:29 PM
Maybe I'm missing something here, but why not use dependent fields?
