javascript: gs.getUser().getRecord().getValue('location') is not Working in Record Producer Kingston

Chaisai
Kilo Expert

Hello There,

 

I have created a Location reference field with table as cmn_location and in the default value i have given as javascript: gs.getUser().getRecord().getValue('location') [have even tried with  javascript: gs.getUser().getLocation() but no luck] which is not working in my Work instance which runs on Kingston. When i try same on my personal Kingston instance it is working as expected. Much appreciated if any suggestions on how to work around on this..

 

Thanks in advance!

11 REPLIES 11

Hi,

Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.

Regards
Ankur

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

verdakosnett
Tera Expert

The solution is to create a script include and query it using the gs.getUserDisplayName() from sys_user;

 

var ServiceCatalogAjax = Class.create();
ServiceCatalogAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

returnUserLocation: function() {


var user=new GlideRecord('sys_user');
user.addQuery('name', gs.getUserDisplayName() );
user.query();
user.next();

return user.location;
},

type: 'ServiceCatalogAjax'
});

 

javascript:yourscopename.ServiceCatalogAjax().returnUserLocation();

find_real_file.png

Hi, Do you just want to populate the location of the logged in user? Regards Ravi

Ian Mildon
Tera Guru

As the Location field is on the user profile you should just be able to use "myUserObject.getLocation() -- returns the current user's location"

Which should only require your script to be:

 

javascript:gs.getUser().getLocation();

Reddy26
Tera Contributor

PFB

javascript:gs.getUser().getRecord().getDisplayValue("location");