- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 11:28 AM
I'm building a small little custom app and the requirement needs me to auto set certain groups based on state.
typically I would do this with assignment rules but I have to also do other things that cannot be done with rules.
That said, I am leveraging UI Policy (if true or if false script blocks).
I have created a glide ajax Script Include in the new custom application scope with client callable checked.
I have created three system properties + system properties category and Module to display the properties in the application.
I have created a UI Policy with condition (state = draft) and then in the execute if true script block I have written a fairly simple glideAjax script.
The issue seems to be with parsing the result. If I gs.warn() on the script include it correctly logs what I want just before calling "return" to send the results back to the client.
Here is the UI Policy Script:
function onCondition() {
try {
g_form.clearValue('assigned_to');
g_form.setDisplay('assigned_to', false);
var ga = new GlideAjax('u_docit_ajax');
ga.addParam('sysparm_name', 'getGSDProperties');
ga.addParam('sysparm_property', 'x_10032_gtd_dev.sn.developers.group');
ga.getXML(myCallBack);
}
catch(err) {
console.log(err);
}
}
function myCallBack(response) {
var answer = response.responesXML.documentElement.getAttribute("answer");
alert('my answer is: ' + answer);
//*** g_form.setValue('fieldname', 'sys_id', 'name') ***//
//g_form.setValue('assigned_to', answer); //answer is coming back as: 'c0c602364f55d20036988ab18110c7f8', 'SN Developers'
}
Here is my Script Include:
var u_docit_ajax = Class.create();
u_docit_ajax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
//u_docit_ajax.prototype = Object.extendsObject(x_10032_gtd_dev.u_docit_ajax.AbstractAjaxProcessor, {
// u_docit_ajax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
/*
* @getGSDProperties - GlideAjax function called from client script
* @sysparm_property - This will be the sys_parameter name passed in from the client
* @returns - The value of the given property
*/
getGSDProperties: function() {
var sysProp = this.getParameter('sysparm_property');
gs.warn('***DEBUG: gs.getProperty(sysProp) is: ' + gs.getProperty(sysProp));
return gs.getProperty(sysProp);
}
});
Here is an error in the system log when the Script Include is processing:
And here is a Java console error when the client-side codes runs when form loads:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2016 11:16 AM
HI Emyrold,
You need to have 2 properties or You need to split the property into display name and sys_id and pass them separately for the setValue method.
Hope this helps
Thanks
Srini

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 04:29 PM
Hi,
I justed tested on my instance and it worked. I was able to set the value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2016 06:14 PM
Simple solution:
Do not use GlideAjax to get System Properties. It is an over-engineered solution.
Instead, do this:
- Create a display business rule in Advanced view for your table
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.sn_developers_group = gs.getProperty('x_10032_gtd_dev.sn.developers.group');
// Add your code here
})(current, previous);
- On your client script
g_form.setValue('assigned_to',g_scratchpad.sn_developers_group );
Yep, that is two lines of code for your solution.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2016 09:13 AM
Hi Paul,
Thanks for the simple suggestion, like it...
However, I'm still having the same issue where the static line sets the value and when I either do the glidAjax or your suggestion with g_scratchpad it still does not set. I'm going to continue to trouble shoot and will start by jslog'ing to triple check if there is a trailing space or something.
//g_form.setValue('assignment_group', 'c0c602364f55d20036988ab18110c7f8', 'SN Developers'); //this static line works
g_form.setValue('assignment_group', g_scratchpad.sn_developers_group); // this is not setting, just leaving the reference field blank.
For the static line, I goto the system property I created, and copy the value and then paste it into the client side script (above) to prevent any possibility of type-o issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2016 09:25 AM
Hi Paul,
Here is my debugging attempts:
jslog('***DEBUG: from scratchpad: ' + g_scratchpad.sn_developers_group);
jslog('***DEBUG: from static: ' + "'c0c602364f55d20036988ab18110c7f8', 'SN Developers'");
***DEBUG: from scratchpad: 'c0c602364f55d20036988ab18110c7f8', 'SN Developers'
***DEBUG: from static: 'c0c602364f55d20036988ab18110c7f8', 'SN Developers'
Any other suggestions, on how to debug to determine why if g_form.setValue() has sys_id and name set statically it works but when I either perform a glideAjax or g_scratchpad it does not?
Thanks,
-e

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2016 09:28 AM
Hi emyrold,
Can you keep an alert statement at the client script and see if you are getting the value
alert( g_scratchpad.sn_developers_group);