- 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 07:52 AM
change this line and check,
ga.addParam('sysparm_sys_id', g_form.getValue('sys_id')); to ga.addParam('sysparm_sys_id',g_form.getUniqueValue());// it returns the sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 07:52 AM
Hi,
Have a check in onSubmit client script and update your client script:
function onSubmit() {
var ga = new GlideAjax('ThisParent');
ga.addParam('sysparm_name', 'checkIncidentChilds');
ga.addParam('sysparm_sys_id', g_form.getValue('sys_id'));
var answer = ga.getXMLWait();
if(answer){
// do nothing
return true;
}
return false;
}
This will stop form submission if answer returning is 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 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:11 AM
I want to force a confirmation message if the answer is 'true' and update the Incident if they hit OK, and if they cancel, it still saves the record with whatever other updates they made.
Nothing should happen when it's false (because the Incident has no children).
