Value of Parameter getting changed to undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2016 06:29 AM
I have one select box variable. My requirement is if I select any value in that field I need to restrict the record in Reference field under that.
See the script below:
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var purpose_change = g_form.getValue('purpose_change');
var ga = new GlideAjax('CheckProcess ');
ga.addParam('sysparm_name','checkPurposeofChange');
ga.addParam('sysparm_purpose_change', purpose_change);
ga.getXML(handleMessage);
function handleMessage(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var parentIncidents = answer.evalJSON();
g_form.clearMessages();
for (i=0;i< parentIncidents.length;i++){
g_form.addInfoMessage("Here is an active incident (major or parent): " + parentIncidents[i].number + " with short description: " + parentIncidents[i].short_description);
}
}
}
Script Include:
var CheckProcess = Class.create();
CheckProcess.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
checkPurposeofChange: function(checks){
var sysIDs = [];
var checks = this.getParameter('sysparm_purpose_change');
if(checks == "org_to_temp")
{
var gre = new GlideRecord('cmdb_ci_server');
gre.addEncodedQuery('u_server_sla_exemption=false');
gre.query();
while(gre.next()){
sysIDs.push(gre.sys_id + '');
}
return 'sys_idIN' + sysIDs;
}
else if(checks == "temp_to_org")
{
var grd = new GlideRecord('cmdb_ci_server');
grd.addEncodedQuery('u_server_sla_exemption=true');
grd.query();
while(grd.next()){
sysIDs.push(grd.sys_id + '');
}
return 'sys_idIN' + sysIDs;
}
},
type: 'CheckProcess'
});
Regards,
Shamma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2016 06:37 AM
Hi Shamma,
If you want to restrict the values in the reference field based on the select/choice field, consider using a reference qualifier on the reference variable. That's what they are built for. No need for a GlideAjax call.
http://wiki.servicenow.com/index.php?title=Reference_Qualifiers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2016 09:40 AM
Hi chuck,
Thanks for your update.
I have one questions. For eg:
var BackfillAssignmentGroup = Class.create();
BackfillAssignmentGroup.prototype = {
initialize: function() {
},
BackfillAssignmentGroup:function() {
var gp = ' ';
var a = current.assigned_to;
//return everything if the assigned_to value is empty
if(!a)
return;
//sys_user_grmember has the user to group relationship
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user',a);
grp.query();
while(grp.next()) {
if (gp.length > 0) {
//build a comma separated string of groups if there is more than one
gp += (',' + grp.group);
}
else {
gp = grp.group;
}
}
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + gp;
},
type: 'BackfillAssignmentGroup'
}
If I am passing this to my script include
var a = current.assigned_to;
How will it take the value of current.assigned_to. For Eg If i have a variable on my record producer Can I access that variable in my script include by using current.variables.purpose_change. purpose_change is my variable name.
Regards,
Shamma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2016 09:50 AM
The script include does not have access to your variables on the record producer. It needs two things, be client callable and extend the abstract ajax processor. Refer to the GlideAjax page.
Docs: Client Scripts
Docs: GlideForm
Docs: GlideAjax
Client Script Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2016 11:23 AM
Hi Chuck,
Does Script include have access to current i.e. field on the form. Can we access the field by using current.field_name.
Also, I tried to use the Glidejax onChange Catalog Client Script and the script Include both are copied above. It is picking up the value of the variable on record producer but then as soon as I am clicking on the Reference Field it changes the value to undefined.That means when I am changing the value of Select Box field it is picking up that value however when I am using that variable value as a condition in my script include there it is showing as undefined. I tried it by using alert and gs.log.
Can you please suggest where m I lacking?
Regards,
Shamma