- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2022 08:16 PM
Hello Reader,
I have created a Catalog Client Script that runs onSubmit, but it is not working as expected. Here, just a record should be updated and nothing in return is required from the server side. I tried doing the same in Global application with 'sys_user' and achieved it. Please see the below code that I wrote for scoped application and please let me know if there are any changes to be made.
Catalog Client Script - onSubmit:
function onSubmit() {
//Type appropriate comment here, and begin script below
var user = g_form.getValue('instructor');
var schedule = g_form.getValue('update_schedule');
schedule = schedule.split(' ');
var date = schedule[0];
var time = schedule[1];
var ga = new GlideAjax('ServiceRequests');
ga.addParam('sysparm_name', 'setUpdatedSchedule');
ga.addParam('sysparm_user', user);
ga.addParam('sysparm_date', date);
ga.addParam('sysparm_time', time);
ga.getXML(setSchedule);
function setSchedule(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
}
}
Script Include:
setUpdatedSchedule: function(){
var user = this.getParameter('sysparm_user');
var date = this.getParameter('sysparm_date');
var time = this.getParameter('sysparm_time');
var gr = new GlideRecord('x_87405_dive_man_courses');
gr.addQuery('instructor', user);
gr.query();
if(gr.next()){
gr.setDisplayValue('date', date);
gr.time = time;
gr.update();
}
},
Thanks
Solved! Go to Solution.
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 12:17 AM
Hi,
Since you are in scoped app don't use gs.log() as it would break your script. you can use gs.info()
You can use workflow run script for this instead of onSubmit and then insert the data
Also update this line
Script Include:
setUpdatedSchedule: function(){
var user = this.getParameter('sysparm_user');
var date = this.getParameter('sysparm_date');
var time = this.getParameter('sysparm_time');
var gr = new GlideRecord('x_87405_dive_man_courses');
gr.addQuery('instructor', user);
gr.query();
if(gr.next()){
gr.date.setDisplayValue(date); // update as this
gr.time = time;
gr.update();
}
},
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
‎07-04-2022 10:12 PM
I think display value causes issue in scoped app, try setValue instaed of set DisplayValue and check if that worls.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2022 11:44 PM
Hi Raghav,
Thank you for the response. The issue here the script include itself is not getting executed. I have added a log on the very first line of the function and that also doesn't seem to be logged into the table.
Please share your views on this.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 12:17 AM
Hi,
Since you are in scoped app don't use gs.log() as it would break your script. you can use gs.info()
You can use workflow run script for this instead of onSubmit and then insert the data
Also update this line
Script Include:
setUpdatedSchedule: function(){
var user = this.getParameter('sysparm_user');
var date = this.getParameter('sysparm_date');
var time = this.getParameter('sysparm_time');
var gr = new GlideRecord('x_87405_dive_man_courses');
gr.addQuery('instructor', user);
gr.query();
if(gr.next()){
gr.date.setDisplayValue(date); // update as this
gr.time = time;
gr.update();
}
},
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader