- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 07:47 AM
I'm trying to setup an onSubmit Client Script that checks if an Incident has any children records (I don't want the OOB BR that auto-resolves children Incidents to run without some kind of verification). No matter what I do, my return value is true and I can't determine why:
Here is my Script Include:
var ThisParent = Class.create();
ThisParent.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkIncidentChilds: function() {
var taskID = this.getParameter('sysparm_sys_id');
var countChilds = new GlideRecord('incident');
countChilds.addQuery('u_parent_incident',taskID);
countChilds.addQuery('active', true);
countChilds.setLimit(1);
countChilds.query();
if (countChilds.hasNext()){ //there is at least one record
return true;
}
else {
return false;
}
},
type: 'ThisParent'
});
and my Client Script:
function onSubmit() {
var ga = new GlideAjax('ThisParent');
ga.addParam('sysparm_name', 'checkIncidentChilds');
ga.addParam('sysparm_sys_id', g_form.getValue('sys_id'));
ga.getXMLWait();
alert(ga.getAnswer());
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 07:53 AM
Hi,
here is the updated script: getUniqueValue() method
function onSubmit() {
var ga = new GlideAjax('ThisParent');
ga.addParam('sysparm_name', 'checkIncidentChilds');
ga.addParam('sysparm_sys_id', g_form.getUniqueValue());
var answer = ga.getXMLWait();
if(answer){
// do nothing
return true;
}
return false;
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
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
05-16-2017 08:01 AM
Mine does...I figured someone would notice that though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 08:01 AM
Think this line is wrong in the script include:
countChilds.addQuery('u_parent_incident',taskID);
My guess you are using the OOB field named parent_incident and not u_parent_incident.
Since that field doesnt exist, it ignores that line and the only addQuery you have is active is true. Which I guess makes that it will always at least find 1 record and return true.
If you only want active records, there is even a OOB query for that like this: countChilds.addActiveQuery();
I would also use the g_form.getUniqueValue() as mention before when setting the sys_id.
//Göran