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

Shubham_Jain
Mega Sage

@Naveen87 @try to use this on Catallg Client Script 

 

function onLoad() {
if (g_form.getParameter('sysparm_referring_record')) {
var parentSysId = g_form.getParameter('sysparm_referring_record');
g_form.setValue('what_is_source_of_exception_requirement', parentSysId);
}
}

 

 

✔️ If this solves your issue, please mark it as Correct.


✔️ If you found it helpful, please mark it as Helpful.



Shubham Jain


@Shubham_Jain ,

Thanks for the response, However no luck.

 

Naveen87_2-1751957881196.png

 

Naveen87_1-1751957859207.png

 

Hello @Naveen87,

 

You can try by creating below onLoad client script and script include.

onLoad Client script - 

function onLoad() {
    // Get URL parameters
    var urlParams = new URLSearchParams(window.location.search);
    var parentSysId = urlParams.get('sysparm_parent_sys_id');
    var parentTable = urlParams.get('sysparm_parent_table');

    // Check if the parent is an incident and if sys_id is present
    if (parentSysId && parentTable === 'incident') {
        // Get the incident number using GlideAjax
        var ga = new GlideAjax('IncidentUtils'); // Name of your Script Include
        ga.addParam('sysparm_name', 'getIncidentNumber'); // Name of the function in your Script Include
        ga.addParam('sysparm_incident_sys_id', parentSysId);
        ga.getXMLAnswer(function(answer) {
            if (answer) {
                g_form.setValue('what_is_source_of_exception_requirement', answer);
            }
        });
    }
}

 

Script Include - 

var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getIncidentNumber: function() {
        var incidentSysId = this.getParameter('sysparm_incident_sys_id');
        var incidentGR = new GlideRecord('incident');
        if (incidentGR.get(incidentSysId)) {
            return incidentGR.number.toString(); // Return the incident number
        }
        return ''; // Return empty string if not found
    },

    type: 'IncidentUtils'
});

 

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

Hello @Naveen87 , you can mark multiple answers as correct answer. 

 

If you feel my answer help you anywhere please mark this also as a accepted solution.

 

Thanks,

Ashish