How to access catalog item sys_id in multi row variable set (MRV) catalog client script?

Hanamant
Tera Expert

How to access catalog item sys_id in multi row variable set (MRV) catalog client script?

4 REPLIES 4

Michael Jones -
Giga Sage

Is this being used in the Service Portal, or in the UI?

If this is being used in the UI, then you can use a line like this in a script (onload or onchange in the variable set): 

var cat_id = window.parent.g_form.getUniqueValue();

 

In the Service Portal, you can do this with some extra setup. 

In an onload script, do the following: note the placement of the variable outside of the onload function: 

function onLoad() {
   //Type appropriate comment here, and begin script below
   
}
cat_id = g_form.getUniqueValue();

Then, inside a script in your variable set, you can just call cat_id to get the value: alert(cat_id); for example. 

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

This is on native UI and I tried your solution but end up with below error from MRV client script:

"TypeError: Cannot read property 'parent'"

 

Finally, it worked when strict javascript mode was disabled from catalog client script ("Isolate script = false") 

The Machine
Kilo Sage

Another option would be something like this.

    var gUrl = new GlideURL();
    gUrl.setFromCurrent();
    var id = gUrl.getParam("sysparm_id");
    alert('ID: ' + id);