Need to Auto-Populate Incident Number in RITM Field from Parent Incident

Naveen87
Tera Guru

Hello Developers,

 

I have a requirement where an RITM is created from an Incident using the 'Relates Search Results' functionality. From there, users can search for a Service Requester and click on ‘Order’, which redirects them to the catalog item using the servicecatalog_cat_item_view form.

In this context, I’d like to auto-populate the field what_is_source_of_exception_requirement on the catalog item with the incident number (i.e., the parent record of the RITM).

 

Here’s the URL being used:

com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=8ea574d297a62290cbf4b976f053af12&sysparm_view=catalog_default&sysparm_parent_table=incident&sysparm_parent_sys_id=096777069726ee50cbf4b976f053af57

 

I attempted this via a client script, but it doesn’t seem to work—likely because client scripts can’t access server-side data like the incident number directly using GlideRecord.

Could you please advise if this can be achieved, and if so, what would be the recommended approach?

 

Thank you!

 

Naveen87_0-1751898981585.png

 

Naveen87_1-1751899039800.png

 

Naveen87_2-1751899226710.png

 

 

 

1 ACCEPTED SOLUTION

@Naveen87 

I already informed to use GlideAjax and query INC table and get number

Another way is to use GlideRecord with callback

Something like this

function onLoad() {

    var gUrl = new GlideURL();
    gUrl.setFromCurrent();
    var incSysId = gUrl.getParam("sysparm_parent_sys_id");

    var gr = new GlideRecord('incident');
    gr.addQuery('sys_id', incSysId);
    gr.query(checkRecord);

    function checkRecord(gr) {
        if (gr.next()) {
            g_form.setValue('what_is_source_of_exception_requirement', gr.number);
        }
    }

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Naveen87 

you should include INC number and not sysId since your variable is string type

use this onLoad catalog client script

If you can't pass INC number then once you get sysId then you can use GlideAjax to query incident with that sysId and get INC number and then set it

function onLoad() {

    var gUrl = new GlideURL();
    gUrl.setFromCurrent();
    var incNumber = gUrl.getParam("sysparm_parent_sys_id");
    g_form.setValue('what_is_source_of_exception_requirement', incNumber);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar ,

Thanks

It's fetching the sys_id of INC.

How do I get the Number?

Naveen87_0-1751959752666.png

 

@Naveen87, you need to make ajax call to get Incident Number. Please refer above solution provided.

 

Please mark this response as Correct and Helpful if it assists you. You can mark more than one reply as an accepted solution.


Thanks,
Ashish

@Naveen87 

I already informed to use GlideAjax and query INC table and get number

Another way is to use GlideRecord with callback

Something like this

function onLoad() {

    var gUrl = new GlideURL();
    gUrl.setFromCurrent();
    var incSysId = gUrl.getParam("sysparm_parent_sys_id");

    var gr = new GlideRecord('incident');
    gr.addQuery('sys_id', incSysId);
    gr.query(checkRecord);

    function checkRecord(gr) {
        if (gr.next()) {
            g_form.setValue('what_is_source_of_exception_requirement', gr.number);
        }
    }

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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

@Ankur Bawiskar ,

It's working.

Is it a best practise to use GlideRecord on Client side?