REQ - defaulting users location

CamUnderwood
Tera Contributor

I've got an interesting situation where we are wanting to default the user's location into the location field on the REQ view, but i can't edit that field, and its pointing to the task table for some reason. 

 

has anyone come across this, and found a work around?

 

the location field actually pulls the sys_user table from what i can see. when i attempt to modify the dictionary entry, it wont let me select a diff table either. 

Screen Shot 2023-07-20 at 11.18.06 AM.png

Screen Shot 2023-07-20 at 11.18.51 AM.png

  

 

 

2 REPLIES 2

Hemanth M1
Giga Sage
Giga Sage

Hi @CamUnderwood ,

 

its an incorrect reference to the location field, you should be able to change to "cmn_location" table are u getting any error/info message during reference change

 

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Riya Verma
Kilo Sage
Kilo Sage

Hi @CamUnderwood ,

 

Hope you are doing great.

 

The first step is to create a Business Rule that triggers when a new REQ record is created. This Business Rule will automatically populate the location field with the user's location.

 

  1. Create a new Business Rule named "Populate Location on REQ Create."
  2. Set the "Table" field to "REQ" to target the REQ table.
  3. Set the "When to run" field to "Before" and "Insert" to trigger the rule when a new record is created.

try using below script for reference :

 

(function executeRule(current, previous) {
    // Check if the location field is empty
    if (!current.location) {
        // Get the current user's sys_user record
        var currentUser = gs.getUser();
        var userLocation = currentUser.getLocation();

        // Set the user's location as the default value for the location field on REQ
        if (userLocation)
            current.location = userLocation;
    }
})(current, previous);

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma