How to get cat item sys_id and use it in Default value of a variable in variable set

eddie_chang
Giga Contributor

I have a variable (u_role) in a variable set and variable set is used on multiple cat items. u_role is a reference field to a table called u_access_roles which contain cat item sys_id (u_application) and roles(u_role2) and default flag (u_default). Now I want to set a default value for u_role variable. For reference qualifier, I use javascript:'u_application='+current.cat_item.sys_id; so list of roles associated with the cat item will be in the list.  For Default Value, I use 

javascript:
var gr = new GlideRecord('u_access_roles');
gr.addQuery('u_application',current.cat_item.sys_id);
gr.addQuery('u_default','true');
gr.query();
gr.next();
gr.getUniqueValue();

This doesn't work. I got error "org.mozilla.javascript.EcmaError: Cannot read property "cat_item" from null".

I then tested the same code in a variable alone, not in the update set, it worked. 

Can anyone help me? How do I get the cat item sys_id for a variable in variable set?

Very much appreciated.

5 REPLIES 5

Prasad43
Tera Guru

Try this to get sys id of current item in portal :

javascript:
var uri = gs.action.getGlideURI();
var sys_id=uri.get('sys_id');
sys_id;