making the requested for readonly

Community Alums
Not applicable

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 

4 REPLIES 4

Nayan  Dhamane
Kilo Sage
Kilo Sage

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.

 

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Community Alums
Not applicable

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?

Hello @Community Alums ,

I am not able to understand your requirement could you please explain in detail.

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

SwarnadeepNandy
Mega Sage

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