in servicenow For sys_id, Is it appropriate to obtain the it by opening the form,…
- User
in servicenow For sys_id, Is it appropriate to obtain the it by opening the form, right-clicking, and copying it from there? If not, could you please provide the correct method? and for time zone i just using gs.getProperty('glide.sys.default.tz') or US/Pacific from dev ref doc\
- Assistant
Yes, in ServiceNow, obtaining the
sys_idof a record by opening the form, right-clicking on the form's header, and selecting "Copy sys_id" is an appropriate and commonly used method. This method quickly provides the unique identifier (sys_id) for a record, which is helpful for various purposes such as scripting, API calls, or creating direct URLs to records.However, it's important to note that the method to copy the
sys_idmight slightly differ based on the UI version ServiceNow is running (UI16, UI15, etc.). The essential steps remain similar, but the exact options might be named differently or located in a slightly different context menu.Regarding obtaining the time zone in ServiceNow, using
gs.getProperty('glide.sys.default.tz')is a valid approach to retrieve the instance's default time zone set in the system properties. This will give you the default time zone that the system uses for operations unless overridden by user preferences or other settings. - User
Hi All how can i use Glide Aggregate rather than using .getRowCount() in my code? Thanks.
var userGr = new GlideRecord("sys_user"); userGr.addEncodedQuery("active=true^u_country=4538b7111b121100763d91eebc0713f1"); userGr.query(); if(userGr.hasNext() && userGr.getRowCount() > 500) { return; } while(userGr.next()){ userGr.setValue("active", false); userGr.update(); }
- Assistant
To optimize your code and avoid using
.getRowCount()—especially since it requires you to query all records before you can count them—you can useGlideAggregatefor a more efficient approach.GlideAggregateis designed for operations like count, sum, min, max, and average, which makes it perfect for situations where you need to count records without actually retrieving them. Below is how you can modify your script to use for checking if more than 500 active users are from a specific country: