Populate the reference variable incident number on catalog item form through url

Not applicable

I have added variable "Task Number" (name = number) referencing to incident table on standard laptop catalog item form (catalog item sysid = 04b7e94b4f7b4200086eeed18110c7fd). Now I want to auto populate the incident number "INC0000001" in Task Number field on catalog item form using url parameter.

I am new to this configuration. Please help me achieve the same.

1 ACCEPTED SOLUTION

@Community Alums 

 

Try as below :

 

1. Create a Variable for Task Number :

 

AmitVerma_0-1724400197127.png

 

2. Configure an On-Load Catalog Client Script as shown below. Ensure that Isolate Script is set to False :

 

AmitVerma_1-1724400345872.png

function onLoad() {
    //Type appropriate comment here, and begin script below
    var taskNumber = getParameterValue('number');
    if (taskNumber) {
        g_form.setValue('number', taskNumber);
    }

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


}

 3. Hit the Catalog Item URL with number as the parameter. I have made use of the URL https://<myinstance>.service-now.com/now/nav/ui/classic/params/target/com.glideapp.servicecatalog_cat_item_view.do%3Fv%3D1%26sysparm_id%3D04b7e94b4f7b4200086eeed18110c7fd%26number%3DINC0010017

 

Output :

AmitVerma_2-1724400546884.png

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

View solution in original post

10 REPLIES 10

vermaamit16
Kilo Patron

Hi @Community Alums 

 

Can you please elaborate on your requirement ? Which URL parameter you are referencing to ?

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

Not applicable

Hi Amit,

 

So when I enter add incident number in url that incident number should populate in Task Number

@Community Alums 

 

Is URL a field on your catalog item ? Can you please share some screenshots for better understanding.

Thanks and Regards
Amit Verma

Not applicable

Hi Amit,

 

I have created Task as field on standard laptop catalog item with Name as task_number and referencing to incident table.

 

Onload client script as below:

function onLoad() {
    var number = getParameterValue('task_number');
    g_form.setValue("task_number", number);
}
function getParameterValue(name) {
var url = top.location.href;
//alert(url);
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
}
}
 
The expectation is when I put below the incident number at the end of url, that incident number should populate in Task field
 
instance.name/now/nav/ui/classic/params/target/com.glideapp.servicecatalog_cat_item_view.do%3Fv%3D1%26sysparm_id%3D04b7e94b4f7b4200086eeed18110c7fd%26task_number%3DINC0010017
 
but the INC0010017 is not populating in Task and its empty only
AnkitaGupte_0-1724182191593.png