How to update a table record onSubmit for a Service Item in scoped application?

Talvin Singh
Tera Expert

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

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Talvin Singh 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

3 REPLIES 3

RaghavSh
Kilo Patron

I think display value causes issue in scoped app, try setValue instaed of set DisplayValue and check if that worls.


Raghav
MVP 2023

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Talvin Singh 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader