How to copy incident fields to request fields while creating request from an incident through 'Create Request' button

Khushboo1
Tera Contributor

Hi all,

I was trying to add 'Create Request' button on Incident form that should redirect to service catalog page, and after opening one of the request form from there it should have some fields like 'requested_for', 'short_description' auto-filled (copied from that incident through which we have clicked on 'create request' ) .

I have added button which is redirecting to service catalog page but doesn't have any idea how can I make those fields on request form prefilled.

Is there any way to do that?

 

8 REPLIES 8

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Khushboo ,

 

There is already an OOB button present on the incident form to create requests from incidents. No need to create new button for that.

find_real_file.png

 

Please mark my answer as helpful/correct if it resolves your query.

 

Regards,

Gunjan Kiratkar

Consultant - ServiceNow, Cloudaction

Rising Star 2022

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi Gunjan, I have not created any new button, i have activated this OOB UI action as a form button. But the problem is it is redirecting to service catalog page, which is fine. But I want that I open any form from service catalog, it should have pre-filled fields

Hi @Khushboo ,

Check out the below thread it will show you how to pass parameters from URL and then fetch that using the client script.

Prepopulate fields on a service catalog item using a URL

3 Ways to Populate Values in ServiceNow via the URL

 

Regards,

Gunjan


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

shloke04
Kilo Patron

Hi @khushboo

In that case, you need to create a UI Action on your Incident form and use the script as below:

var url = '/sp?id=sc_cat_item&sys_id=3f1dd0320a0a0b99000a53f7604a2ef9&sysparm_caller='+ current.caller_id +'&sysparm_shortDescription='+ current.short_description+'&sysparm_Category='+current.category;
action.setRedirectURL(url);

Screenshot of UI Action below:

find_real_file.png

So when you will click on the button on your Incident form it will form the URL with the value which you need and then you need to follow below steps:

1) Write a On Load Catalog Client Script on your Catalog Item and use the script as below:

function onLoad() {

    //Use the 'getParameterValue' function below to get the parameter values from the URL   

    var user = getParameterValue('sysparm_caller');
    var ShortDescription = getParameterValue('sysparm_shortDescription');

    if (user) {

        g_form.setValue('caller', user); // Replace "caller" with your Caller variable

    }
    if (ShortDescription) {
        g_form.setValue('description', user);// Replace "description" with your Variable Name
    }

}

function getParameterValue(name) {

    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

    var regexS = "[\\?&]" + name + "=([^&#]*)";

    var regex = new RegExp(regexS);

    var results = regex.exec(top.location);

    if (results == null) {

        return "";

    } else {

        return unescape(results[1]);

    }

}

 

This way you can add your other variable as well. This is working for me as shown below:

Result:

find_real_file.png

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

 
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke