Client Script Glide Ajax condition check
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 09:38 AM
Hello,
I would like to change the when to run condition on this client script from hardcoded to query incident gliderecord and return true if record matches category and assigned to groups. The client script is using GlideAjax to check another value. This part is working I would just like to surround this with another GlideAjax to check condition. In other words take this
if (g_form.getValue('category') == 'transmission' && g_form.getValue('assignment_group') == '780847e51ba07910783f43b1b24bcb91' || g_form.getValue('assignment_group') == 'c13ba3c11bd0f1106bf5535b234bcbc3' || g_form.getValue('assignment_group') == '644b63c11bd0f1106bf5535b234bcbfe'). and change into if(answer).
====================================================
Script Include: ITSMAjaxUtils
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 12:32 PM
Hi Chad,
I'm not following exactly why on earth you would want to do this, especially since it means a call to the server on every change of whatever field, even though it might not be needed. In any event, keep it simple with one trip to the server and back. Have the first function call the second function before returning an answer.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var curSysid = g_form.getUniqueValue();
var ga = new GlideAjax('ITSMAjaxUtils');
ga.addParam('sysparm_name', 'property_util');
ga.addParam('sysparm_inc_id', curSysid);
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == '0') {
alert('Please attach all impacted countries to the incident form before updating the incident state');
//return false; //not applicable in onChange script
}
}
}
var ITSMAjaxUtils = Class.create();
ITSMAjaxUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
property_util: function() {
var answer = '';
var inc_id = this.getParameter('sysparm_inc_id');
var incident = new GlideRecord('incident');
var encquery = 'category=transmission^assignment_group=c13ba3c11bd0f1106bf5535b234bcbc3^ORassignment_group=644b63c11bd0f1106bf5535b234bcbfe^ORassignment_group=780847e51ba07910783f43b1b24bcb91';
incident.addQuery("sys_id", inc_id);
incident.addEncodedQuery(encquery);
incident.query();
if (incident.next()) {
answer = getIncImpactedCountries(inc_id);
}
return answer;
},
getIncImpactedCountries: function(inc_id) {
//your existing working function, including the return - which will be returned to the previous function in this case instead of back to the client.
},
type: 'ITSMAjaxUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 04:49 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 10:06 PM
Hi,
Try printing the answer first in alert, then based on the received response you can do the rest things.
alert(answer); // this will give you whatever you have received from server.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 06:24 AM
Hello,
We are going to go another direction so this is no longer needed. Appreciate all the responses.
Thanks,
Chad