Script not working in Agent Workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2019 11:54 PM
We have some scripts which removes Category values based on the view. The below category is working fine in Incident 'default view' , however it doesn't work in Agent Workspace. I have changed the UI type to All but it still doesn't work. Is it true that GlideRecord is not supported in Agent workspace at all?
Can someone help or convert this into GlideAjax to get it working if possible?
function onLoad() {
var sd = false;
//Type appropriate comment here, and begin script below
var objView = document.getElementById('sysparm_view');
var strView = objView.getAttribute('value');
var category = g_form.getValue('category');
var ri = new GlideRecord('sys_choice');
var asgrp = g_form.getValue('assignment_group');
if (asgrp != '070a28ca0a0aa02e01ac6d7bd6ddab6b' && asgrp != '6dfbd5f00a0aa02e01f7eebe4998eb13' && asgrp != '070a26580a0aa02e009bb544858499a7') {
sd = false;
} else {
sd = true;
}
// hide GBO OPTIONS FOR CATEGORY
if (strView != 'GBO' && category.indexOf('GBO -') < 0 && !sd) {
ri.addQuery('element', 'category');
ri.addQuery('label', 'LIKE', 'GBO -');
ri.query();
while (ri.next()) {
g_form.removeOption('category', ri.value, ri.label);
}
} else if (sd) {
return;
} else {
// hide other category for GBO SRM
//var ri = new GlideRecord('sys_choice');
ri.addQuery('element', 'category');
ri.addQuery('label', 'DOES NOT CONTAIN', 'GBO -');
ri.query();
while (ri.next()) {
g_form.removeOption('category', ri.value, ri.label);
}
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 07:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 01:06 AM
Hi,
Can you add some alerts and check till where it is coming and what error are you getting? That should help you to find out the issue. If not, add alerts and share the output and i can help you.
Mark the comment as a correct answer and helpful if this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 01:13 AM
Also,to remove options, you don't need a label. so use like this
g_form.removeOption('category', ri.value);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2019 11:46 PM
Hi,
Did you add alerts and check? Could you share your latest script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2019 02:45 AM
Hi,
Here you go:
function onLoad() {
var sd = false;
//Type appropriate comment here, and begin script below
var objView = document.getElementById('sysparm_view');
var strView = objView.getAttribute('value');
var category = g_form.getValue('category');
var asgrp = g_form.getValue('assignment_group');
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.addParam('sysparm_strView',strView);
ga.addParam('sysparm_cat',category);
ga.addParam('sysparm_asgrp',asgrp);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer != 'false'){
var spl1;
spl1 = answer.split(',');
for(var i=0;i<spl1.length;i++){
var abc = spl1[i].split('-');
g_form.removeOption('category', abc[0], abc[1]);
}
}
}
Script include:
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getback : function(){
function onLoad() {
var sd = false;
var arr = [];
var arr1 = [];
var ri = new GlideRecord('sys_choice');
var asgrp = this.getParameter('sysparm_asgrp');
var cat = this.getParameter('sysparm_cat');
var strView = this.getParameter('sysparm_strView');
if (asgrp != '070a28ca0a0aa02e01ac6d7bd6ddab6b' && asgrp != '6dfbd5f00a0aa02e01f7eebe4998eb13' && asgrp != '070a26580a0aa02e009bb544858499a7') {
sd = false;
} else {
sd = true;
}
// hide GBO OPTIONS FOR CATEGORY
if (strView != 'GBO' && category.indexOf('GBO -') < 0 && !sd) {
ri.addQuery('element', 'category');
ri.addQuery('label', 'LIKE', 'GBO -');
ri.query();
while (ri.next()) {
arr.push(ri.value+'-'+ri.label+'');
}
return arr.toString();
} else if(sd) {
return 'false' ;
} else {
ri.addQuery('element', 'category');
ri.addQuery('label', 'DOES NOT CONTAIN', 'GBO -');
ri.query();
while (ri.next()) {
arr1.push(ri.value+'-'+ri.label+'');
g_form.removeOption('category', ri.value, ri.label);
}
return arr1.toString();
}
}
},
type: 'HelloWorld'
});
Thanks,
Ashutosh
Mark the comment as a correct answer and helpful if this helps.