The CreatorCon Call for Content is officially open! Get started here.

getreference

Ashley
Kilo Sage

Hello,

First attempt at scripting:

I am trying to write a client script within a Variable Set that returns the current logged in user Floor, managed to get Location, Department etc working as these have pre-built methods:

Floor is a custom field that has been added so wont work,

Here is the script I have so far which is currently not working:

______________________________________________________________

function onChange(control, oldValue, newValue, isLoading) {

  var userLocID = g_form.getReference('u_locationid', Display);

  }

function Display(userLocID) {

  if (userLocID != ' ')

  g_form.setValue('Floor', userLocID);

  }

Comments:

u_locationid is the Column Name on the User Table where the Floor is added as part of the import

Floor is the name of the field on the New User Request Form

Any help would be appreciated

Ashley

1 ACCEPTED SOLUTION

Hi Tanaji,



Thank you for your reply



I should have updated this ticket a bit sooner,



I worked with one of the developers in the office to get this working and here is the code we used:



function onLoad() {


var userLocID = g_user.userID;


var FloorQ = new GlideRecord('sys_user');


FloorQ.addQuery('sys_id', userLocID);


FloorQ.query();


if (FloorQ.next()) {        


g_form.setValue('u_floor', FloorQ.u_locationid);   }


}


View solution in original post

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Ashley,



In addition you can refer the example below and adjust your solution accordingly. This script populates the location as soon as the caller field is changed on the incident table.


https://yourinstancename.service-now.com/sys_script_client.do?sys_id=5e524025c0a80166004d1761e85e205...



I hope this helps


Hi Peadeep,



Thank you for the reply but I can't get the page to open, getting a "This webpage is not available" error.


Make sure to replace "yourinstancename" with the name of your instance in the URL. Should load up fine then.