Auto populate catalog item fields from the incident record

NeilCarloB
Tera Contributor

Hello

I have a requirement that will auto populate the catalog item field based on the incident record basically from creating request in incident table and selecting catalog item fields will auto populate. Please check my code is now working (catalog client script).

function onLoad() {
    // Retrieve the 'sysparm_parent_sys_id' (which is the incident sys_id) from the URL
    var incidentSysId = g_url.getParameter('sysparm_parent_sys_id');

    // Check if the 'incident_sys_id' is available
    if (incidentSysId) {
        var gr = new GlideRecord('incident');  // Create a GlideRecord object to query the incident table
        if (gr.get(incidentSysId)) {
            // Retrieve necessary fields from the incident record
            var shortDescription = gr.short_description;
            var description = gr.description;
            var callerId = gr.caller_id;

            // Log the retrieved values (for debugging)
            console.log('Short Description:', shortDescription);
            console.log('Description:', description);
            console.log('Caller ID:', callerId);

            // Set values in the Catalog Item form using 'g_form.setValue'
            if (shortDescription) {
                g_form.setValue('u_short_description', shortDescription);  // Populate 'u_short_description' field
            }
            if (description) {
                g_form.setValue('u_description', description);  // Populate 'u_description' field
            }
            if (callerId) {
                g_form.setValue('u_caller_id', callerId);  // Populate 'u_caller_id' field
            }
        } else {
            console.log('Incident record not found.');
        }
    } else {
        console.log('Incident sys_id not passed to the catalog item.');
    }
}
0 REPLIES 0