Making a reference variable in Service Catalog read only.

Matt W
Giga Contributor

I've created some variables on a catalog item that are references to things like Manager name, location and department and then added an on load client script to populate the users information when the requesters name is inputted on the form.

What I would like to do is make the requesters manager, location and department read only. The problem I am getting is that when I've created a UI Policy Action it starts of read only but when the fields are populated they don't remain read only.

Is there a way to make them read only even after they have been populated?

Thanks in advance.

1 ACCEPTED SOLUTION

Ok. Use the below code with uses getReference Callback. Since GlideRecord is not a good practice to use in Client Script. Run this and let me know, if there are still issues.

Also confirm there is no other UI policy or client script that is marking these field editable?

 

function onChange(control, oldValue, newValue, isLoading) {

if(newValue){
var grUser = g_form.getReference('staff_name', popCallerInfo);
}

//Nested 'getReference' callback function for variable access
function popCallerInfo(grUser){
g_form.setValue('u_job_title' , grUser.title); //set job title
g_form.setValue('u_department' , grUser.department); //set department
g_form.setValue('u_location' , grUser.location); //set location
g_form.setValue('u_contact_number' , grUser.mobile_phone); //use mobile phone field to set contact number
g_form.setValue('u_manager_name' , grUser.manager); //set job title
}
}


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

When Client script runs it blocks the user interaction. So when we make a GlideRecord which is a Synchronous call can freeze the form, if you are querying through thousands of record. If you you a callback function or Glideajax, they are asynchronous. So they dont block the form. You will get good information in the below article.

https://snprotips.com/blog/2016/2/6/gliderecord-client-side-vs-server-side


Please mark this response as correct or helpful if it assisted you with your question.

Thanks for all your help.