making the requested for readonly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:03 AM
I have created one record Producer, in a record producer i have created one variable called the Requested for,
i want to make the requested for readonly when the requested for user belongs to only one location?
can someone please let me know how i can achieve this.
please give your reply as soon as possible as it is urgent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:08 AM
Hello @Community Alums ,
Please let me know how would you know who is the requested for and analyse its location if the field is read only.
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:31 AM
I have written the below script
var read = current.variables.requestor_s_name;
var count = 1;
var br = new GlideRecord('cmn_location');
br.addQuery('account.u_corporate_account', read.account);
br.query();
//br.getRowCount();
while(br.next())
{
if(br.getRowCount() == conut);
{
gs.setReadonly('current.variables.requestor_s_name' , true);
}
}
could you please check?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:43 AM
Hello @Community Alums ,
I am not able to understand your requirement could you please explain in detail.
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 02:35 AM
Hello @Community Alums,
To make the requested for field read-only when the user belongs to only one location, you can use a client script on the record producer.
One possible client script that could achieve your requirement is:
function onLoad() {
//Get the value of the requested for field
var requestedFor = g_form.getValue(‘requested_for’); //Query the sys_user table to find the user record
var userGR = new GlideRecord(‘sys_user’);
userGR.get(requestedFor); //Get the value of the location field
var location = userGR.getValue(‘location’); //Query the sys_user table again to find how many users have the same location
if (location == "<your desired location>") { //You can use your location sys_id or any other location comparision
g_form.setReadOnly(‘requested_for’, true);
} else {
g_form.setReadOnly(‘requested_for’, false);
}
}
This script will run when the record producer form is loaded, and check if the users location is your set location and make the requested_for readonly.
You can modify this script according to your needs and preferences.
I hope this helps.
Kind Regards,
Swarnadeep Nandy