Copying variable values of RITM to a record Producer via UI Action

DPrasna
Tera Contributor

Hi All,

 

I have a requirement to create a button on RITM form that converts the current RITM to an Incident.

I am trying to redirect the UI action to a record producer as below

 

var ritmNumber = g_form.getValue('number');
        var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=62fb775337fasergfgtne012';
        window.open(url);
 
However I need help with copying the variable values for current RITM and set/populate it to the variable values of the record producer. How do I do it?
Need help on the same
 
 
15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

@DPrasna 

include those RITM variables as URL parameter and then use onLoad catalog client script to fetch and set on catalog form

Redirect from a UI Action to a Catalog Item and set default values 

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

try this

var ritmNumber = g_form.getValue('number');
var shortDescription = g_form.getValue('short_description');
 var impact = g_form.getValue('impact');   var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=62fb775337fasergfgtne012' + '&sysparm_variables=ritm_number=' + encodeURIComponent(ritmNumber) + '^short_description=' + encodeURIComponent(shortDescription) + '^impact=' + encodeURIComponent(impact);
 window.location = url;

Rajesh Chopade1
Mega Sage

Hi @DPrasna 

As per understanding your goal is to capture the variable values from the RITM and pass them to the record producer, which will then create an Incident with those values pre-filled.

 

If yes, then first, you'll need to grab the values of the variables associated with the current RITM.

 

You'll create a URL to redirect the user to the record producer form (a Service Catalog item). You can pass the values of the variables via query parameters in the URL. Record Producers can be pre-populated using these parameters.

 

The record producer can then take these query parameters and use them to set the values for the corresponding variables on the form.

function convertRITMToIncident() {
    // Get the current RITM variables
    var issueType = g_form.getValue('u_issue_type');
    var priority = g_form.getValue('u_priority');
    var description = g_form.getValue('u_description');
    var ritmNumber = g_form.getValue('number');

    // Construct the URL for the Record Producer with the pre-populated values
    var recordProducerUrl = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=62fb775337fasergfgtne012' +
                            '&u_issue_type=' + encodeURIComponent(issueType) +
                            '&u_priority=' + encodeURIComponent(priority) +
                            '&u_description=' + encodeURIComponent(description) +
                            '&ritm_number=' + encodeURIComponent(ritmNumber);  // Pass RITM number if needed

    // Open the Record Producer in a new window
    window.open(recordProducerUrl);
}

 

then you need to ensure that the record producer form is set up to accept these query parameters. You can do this by creating a Catalog Client Script (onLoad) in the record producer.

function onLoad() {
    // Check if the query parameters exist
    if (g_request.getParameter('u_issue_type')) {
        g_form.setValue('u_issue_type', g_request.getParameter('u_issue_type'));
    }
    if (g_request.getParameter('u_priority')) {
        g_form.setValue('u_priority', g_request.getParameter('u_priority'));
    }
    if (g_request.getParameter('u_description')) {
        g_form.setValue('u_description', g_request.getParameter('u_description'));
    }
    if (g_request.getParameter('ritm_number')) {
        g_form.setValue('u_ritm_number', g_request.getParameter('ritm_number'));  // You can set this value to a hidden field if needed
    }
}

 

I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

Rajesh

 

DPrasna
Tera Contributor

Hi All,

 

I tried in different ways but none worked.

@Rajesh Chopade1 @Ankur Bawiskar @sravya chipilla 

 

var opened_by = g_form.getValue('opened_by');
    var priority = g_form.getValue('priority');
    var description = g_form.getValue('description');
    var short_description = g_form.getValue('short_description');
    var business_service = g_form.getValue('business_service');
    //var ritmNumber = g_form.getValue('number');

    // Construct the URL for the Record Producer with the pre-populated values
    var recordProducerUrl = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=62fb775337f9fe00e54b0ba754990ea1' +
                            '&opened_by=' + encodeURIComponent(opened_by) +
                            '&priority=' + encodeURIComponent(priority) +
                            '&description=' + encodeURIComponent(description); +
                            '&business_service=' + encodeURIComponent(business_service);
                            + '&short_description=' + encodeURIComponent(short_description);  // Pass RITM number if needed

    // Open the Record Producer in a new window
    window.open(recordProducerUrl);
    }
}
 
Onload:
 

 

function onLoad() {
    if (g_request.getParameter('opened_by')) {
        g_form.setValue('opened_by', g_request.getParameter('opened_by'));
    }
    if (g_request.getParameter('priority')) {
        g_form.setValue('priority', g_request.getParameter('priority'));
    }
    if (g_request.getParameter('description')) {
        g_form.setValue('description', g_request.getParameter('description'));
    }

}