Auto populate field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 02:00 PM
How to auto populate "location" field based on "company" field in alm_hardware table in servicenow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 02:33 PM
To auto-populate the "location" field based on the "company" field in the alm_hardware table in ServiceNow, you can use a Business Rule to set the location when a new hardware record is created or updated.
Follow these steps to create a Business Rule:
- Navigate to "System Definition > Business Rules" in ServiceNow.
- Click "New" to create a new Business Rule.
- Enter the following details:
- Name: "Auto Populate Location based on Company"
- Table: "alm_hardware"
- When: "before"
- Insert: Check the box
- Update: Check the box
- In the "Advanced" tab, paste the following code into the "Script" field:
jsCopy code (function executeRule(current, previous /*null when async*/) { if (current.company.nil()) { return; } // Replace this with the actual logic to determine the location based on the company var location = getLocationBasedOnCompany(current.company); if (location) { current.location = location; } })(); function getLocationBasedOnCompany(company) { // Add your logic here to get the location based on the company. // This is just a simple example, you may need to use GlideRecord to query the location data var location; if (company == 'company_a_sys_id') { location = 'location_a_sys_id'; } else if (company == 'company_b_sys_id') { location = 'location_b_sys_id'; } return location; }
- Click "Submit" to save the Business Rule.
Replace the example code in the getLocationBasedOnCompany function with your own logic to determine the appropriate location based on the company. You may need to use GlideRecord queries to fetch location data from the cmn_location table or any other table that stores your location data.
Now, whenever a new hardware record is created or updated in the alm_hardware table, the "location" field will be auto-populated based on the "company" field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 02:43 PM
Hi @Helio-matos ,
OOB, The location field on the alm_hardware form gets autopopulated from the 'assigned_to' field.
Please search for this client script : Set Loc/CC/Dep/Com from assigned to
The company field references to the 'core_company' table which does not have the location field.
If my answer has helped with your question, please mark it as helpful
Thanks!!