The Zurich release has arrived! Interested in new features and functionalities? Click here for more

I have a requirement to capture value of requested for while redirecting user to another form

sneha_chauhan
Tera Expert

I have a requirement to capture value of requested for while redirecting user to another catalog item form when a specific value is selected in service affected dropdown. Requested for is a reference field which is editable. I am able to redirect to new form using client script but I am not able to pass the value of requested for. Kindly help

1 ACCEPTED SOLUTION

@sneha_chauhan 

you will also need an onLoad client script on the other catalog item to get the value from URL and populate that

Did you add that script?

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

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@sneha_chauhan 

you can get the value and include that as url parameter while you redirect

please share your current script

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

sneha_chauhan
Tera Expert

Hi @Ankur Bawiskar ,

 

Please find below the script I am using currently for redirecting to new catalog item:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var msAjax = new GlideAjax('MIDServerAjax');
    msAjax.addParam('sysparm_name', 'getInstanceURL');
    msAjax.getXMLAnswer(
        function(answer) {
            var instanceUrl = answer;

            if (window == null) {
                var valuePortal = g_form.getDisplayValue('service_affected');
               
                if (valuePortal == "Epic") {

                    top.window.onbeforeunload = null;
                    //top.window.onunload = null;
                    g_form.modified = false;

                    var urlEmail = instanceUrl + "abcdportal?id=sc_cat_item&sys_id=525de4751b546510e5ba6461604bcde5";

                    top.window.location = urlEmail;
            //var edge=g_scratchpad.edge;
                    //alert(edge);
                }

            } else {
                var valueNative = g_form.getDisplayBox('service_affected').value;
                if (valueNative == "Epic") {

                    top.window.onbeforeunload = null;
                    //top.window.onunload = null;
                    g_form.modified = false;

                    var urlEmail1 = instanceUrl + "/abcdportal?id=sc_cat_item&sys_id=525de4751b546510e5ba6461604bcde5";

                    top.window.location = urlEmail1;
                }

            }


        });
}

@sneha_chauhan 

try this

var urlEmail = instanceUrl + "abcdportal?id=sc_cat_item&sys_id=525de4751b546510e5ba6461604bcde5&sysparm_requestedFor=" + g_form.getValue('requested_forVariable');

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

sneha_chauhan
Tera Expert

Hi @Ankur Bawiskar ,

 

I am getting the sys_id of the requested for in the redirected URL but its not setting up the variable value on the form. Variable name for both the fields is same (caller_id).

                    var urlEmail = instanceUrl + "abcdportal?id=sc_cat_item&sys_id=525de4751b546510e5ba6461604bcde5&sysparm_caller_id=" + g_form.getValue('caller_id');