Default value for Reference variable

Ben Draeger
Tera Expert

Hi folks, 

I'm looking to define the default value for a reference variable on a catalog item based on if the person logged in completing the form matches the assigned_to of the computer asset. 

The variable is referencing cmdb_ci_computer table and called 'ref_hostname', I was thinking something like this but I seem to be missing something?

javascipt:if (gs.getUserID = current.assigned_to)ref_hostname = current.name

find_real_file.png

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

Please try below in Default value:

javascript: var comp = new GlideRecord('cmdb_ci_computer'); comp.get('assigned_to',gs.getUserID());comp.getUniqueValue();

 

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

4 REPLIES 4

Murthy Ch
Giga Sage

@Ben Draeger 

Are you trying the set the default value from cmdb_ci_computer table where assigned to is the looged-in user?

If yes how do you want to set if loggedin user has more than 1 record?

 

Thanks

Murthy

Thanks,
Murthy

Anil Lande
Kilo Patron

Hi,

Please try below in Default value:

javascript: var comp = new GlideRecord('cmdb_ci_computer'); comp.get('assigned_to',gs.getUserID());comp.getUniqueValue();

 

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thanks Anil, worked like a charm. 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

javascript: var val=''; var rec = new GlideRecord('cmdb_ci_computer'); if(comp.get('assigned_to',gs.getUserID())) val = comp.getUniqueValue(); val;

Regards
Ankur

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