Glide ajax passing function arguments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â09-02-2020 02:12 AM
Creating a client script to prevent reassignment of incident on certain condition , with the help of script include.
The function in the script include is defined as
isInAssignmentGroupBG:function(assignGrp,user){
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery('group',assignGrp);
gr.addQuery('user',user);
gr.query();
if(gr.next()){
return true;
}
else{
return false;
}
},
I Creating a client script for onsubmit, where i am not able to understand how can i pass values form form to parameters of script include.
function onSubmit() {
//Type appropriate comment here, and begin script below
var assignGrp = g_form.getValue('assignment_group');
var assignTo =g_form.getValue('assigned_to');
var ga = new GlideAjax('IsInAssignmentGroup');
ga.addParam('sysparm_name', 'isInAssignmentGroupBG');// i dont know how to pass parameters to this function for result
ga.addParam('sysparm_user_name', "Bob");
ga.getXML(grpMem);
function grpMem(answer){
var isMember = response.responseXML.documentElement.getAttribute(answer);
if (answer == true){
//how to cancel on form submit with error??
}
else {
//allow form submit
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â09-02-2020 02:29 AM
Hi Karan,
the issue is since you are using onSubmit client script and using Asynchronous GlideAjax the form won't wait till response comes from script include and may submit
So you can write before update BR instead and stop form submission
BR: Before update
Condition: Assignment Group changes && Assigned to changes
Script:
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery('group',assignGrp);
gr.addQuery('user',user);
gr.query();
if(gr.next()){
gs.addErrorMessage('Your Message Here');
current.setAbortAction(true);
}
If you still require client script and how to send the value then use this
Syntax of sending and receiving below
Script Include:
isInAssignmentGroupBG:function(){
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery('group', this.getParameter('sysparm_group'));
gr.addQuery('user', this.getParameter('sysparm_user'));
gr.query();
if(gr.next()){
return true;
}
else{
return false;
}
}
Client Script:
var ga = new GlideAjax('IsInAssignmentGroup');
ga.addParam('sysparm_name', 'isInAssignmentGroupBG');// i dont know how to pass parameters to this function for result
ga.addParam('sysparm_user', g_form.getValue('assigned_to'));
ga.addParam('sysparm_group', g_form.getValue('assignment_group'))
ga.getXML(grpMem);
Regards
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
â09-02-2020 02:41 AM
Hi Karan,
To cancel or Abort the answer should be in the Submit Loop, Then only Onsubmit Works. If we use Asynchronous GlideAjax the form won't wait till response comes from script include and even before the answer comes from the Script include form submits.
We do have an alternative for this Thing.
The Script which you posted, try to achieve this using Onchange Client Script and answer which comes from the script include store it in some field in the table(Which Acts as Flag). Then Create an Onsubmit client script by making use of that field. (If Answer is true then don't allow him to submit and vice versa).
Else
You can proceed with Ankur's Reply.
Code which you posted, there is small modification.
function grpMem(answer){
var isMember = response.responseXML.documentElement.getAttribute(answer);
if (isMember == true){
//how to cancel on form submit with error??
}
else {
//allow form submit
}
Please let me know if you have any additional questions.
Thanks
Vamshidhar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â09-04-2020 08:18 AM
Hi Karan,
Hope you are doing good.
Did you get a chance to check on the solution provided to resolve your query?
If so, please mark appropriate answer as correct & helpful to close the thread.
Regards
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
â09-22-2020 09:55 PM
Hi Karan,
Hope you are doing good.
Did you get a chance to check on the solution provided to resolve your query?
If so, please mark appropriate answer as correct & helpful to close the thread.
Regards
Ankur
Ankur
âš Certified Technical Architect || âš 9x ServiceNow MVP || âš ServiceNow Community Leader