need help in auto populating catalog item 1 variable values in to catalog item 2 variables

priyanka chodip
Tera Contributor

Hi there,

I have a requirement where I need to create Catalog Item 1 (considered the parent) with two variables: Manager and Employee.

Once Catalog Item 1 is submitted (ordered), it should trigger an email notification to the Manager. In the body of the email, there will be a link to Catalog Item 2.

When the Manager clicks this link and Catalog Item 2 form loads, the same two variables (Manager and Employee) on Catalog Item 2 should automatically populate with the values submitted in Catalog Item 1.

I'm not exactly sure how to implement the value passing and auto-population. Could you please guide me on how to set this up?

thanks 
priya

2 ACCEPTED SOLUTIONS

J Siva
Tera Sage

Hi @priyanka chodip 

1. First build the custom URL format as required and use that in the email notification
Syntax:  

https://<INSTANCE-ID>.service-now.com/sp?id=sc_cat_item&sys_id=<CAT ITEM SYS ID>&<VARIABLE 1>=<VALUE 1>&<VARIABLE 2>=<VALUE 2>

Ex:

https://dev22XXX.service-now.com/sp?id=sc_cat_item&sys_id=f15ca9c397011210e46cb73de053af7d&manager=6...

 

2. Create On-Load as below to map the URL parameters to the catalog itm variables.

function onLoad() {
    var manager_url = getParameterValue('manager'); // URL PARATMETER
    var employee_url = getParameterValue('employee'); // URL PARATMETER
    if (manager_url) {
        g_form.setValue('manager', manager_url); // SETTING CAT VARIABLE
    }
    if (employee_url) {
        g_form.setValue('employee', employee_url); // SETTING CAT VARIABLE
    }
}

function getParameterValue(name) {
    var url = top.location.href;
    var value = new URLSearchParams(url).get(name);
    if (value) {
        return value;
    }
}


Regards
Siva

 

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@priyanka chodip 

if you are using flow designer then check my blog on how to add link and in that LINK to 2nd catalog item include the variable values for both the variables, then use onLoad catalog client script on 2nd item to get the values from URL and populate them

ServiceNow Flow Designer: Adding Record Link in "Send Email" flow action 

1) form the URL like this /sp?id=sc_cat_item&sys_id=catItemSysId2&sysparm_manager=<flowVariableManager>&sysparm_employee=<flowVariableEmployee>

2) onLoad catalog client script

function onLoad() {

    try {
        var url = top.location.href;
        if (window == null) {
            // for portal
            var manager = new URLSearchParams(url).get("sysparm_manager");
            var employee = new URLSearchParams(url).get("sysparm_employee");
            g_form.setValue('managerVariable', manager);
            g_form.setValue('employeeVariable', employee);
        }
    } catch (ex) {
        // for native
        var gUrl = new GlideURL();
        gUrl.setFromCurrent();
        var manager1 = gUrl.getParam("sysparm_manager");
        var employee1 = gUrl.getParam("sysparm_employee");
        g_form.setValue('managerVariable', manager1);
        g_form.setValue('employeeVariable', employee1);
    }
}

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

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@priyanka chodip 

if you are using flow designer then check my blog on how to add link and in that LINK to 2nd catalog item include the variable values for both the variables, then use onLoad catalog client script on 2nd item to get the values from URL and populate them

ServiceNow Flow Designer: Adding Record Link in "Send Email" flow action 

1) form the URL like this /sp?id=sc_cat_item&sys_id=catItemSysId2&sysparm_manager=<flowVariableManager>&sysparm_employee=<flowVariableEmployee>

2) onLoad catalog client script

function onLoad() {

    try {
        var url = top.location.href;
        if (window == null) {
            // for portal
            var manager = new URLSearchParams(url).get("sysparm_manager");
            var employee = new URLSearchParams(url).get("sysparm_employee");
            g_form.setValue('managerVariable', manager);
            g_form.setValue('employeeVariable', employee);
        }
    } catch (ex) {
        // for native
        var gUrl = new GlideURL();
        gUrl.setFromCurrent();
        var manager1 = gUrl.getParam("sysparm_manager");
        var employee1 = gUrl.getParam("sysparm_employee");
        g_form.setValue('managerVariable', manager1);
        g_form.setValue('employeeVariable', employee1);
    }
}

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