getUniqueValue() returning undefined in email script

Raymond Norvell
Tera Contributor

I'm having issues when using getUniqueValue(). I'm attempting to retrieve the sys_id as as string to build a link to a particular demand. Code below is what I'm using and calling the variable 'dmnNameLink' immediately after. 

var dmnNameLink = '<a href="https://' + gs.getProperty('instance_name') + '.service-now.com/nav_to.do?uri=dmn_demand.do?sys_id=' + dmnGr.getUniqueValue() + '">' + dmnGr.short_description + '</a>';

The issue is that when I view the output the value of dmnGr.getUniqueValue() I keep getting 'undefined'. Any ideas why? This very same method is working in an almost identical script for project records, the only difference being that there the variable names are different. Here's the working example of that:

var projNameLink = '<a href="https://' + gs.getProperty('instance_name') + '.service-now.com/nav_to.do?uri=pm_project.do?sys_id=' + projGr.getUniqueValue() + '">' + projGr.short_description + '</a>';

^This one works great... Not sure what the issue is.

4 REPLIES 4

Mike Patel
Tera Sage

instead you can also try using .sys_id

EX: 

 

 

var dmnNameLink = '<a href="https://' + gs.getProperty('instance_name') + '.service-now.com/nav_to.do?uri=dmn_demand.do?sys_id=' + dmnGr.sys_id + '">' + dmnGr.short_description + '</a>';

 

 

I tried this as well and it also comes back undefined. I also read here that using getUniqueValue() is preferred over .sys_id as it guarantees a string value where .sys_id might return either a string or type object. I'm not completely sure on that myself however.

Manmohan K
Tera Sage

Hi @Raymond Norvell ,

 

There is nothing wrong with the link code you are using. I recreated it on my PDI and it is working.

Please check how you are getting the demand record set in dmnGr. There might be some problem in that code

Hi Manmohan, thanks for the response. This is how I'm getting the demand record (note that this is being run when a demand task is assigned):

var dmnGr = new GlideRecord('dmn_demand');
dmnGr.get(current.sub_tree_root);