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

SanjivMeher
Kilo Patron
Kilo Patron

The UI policy should work fine. I guess there will be an issue with your script which populates these related fields. Can you share your script? Also I think it should be an onChange Client Script.


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

Matt W
Giga Contributor

Please see script below. To confirm I meant onChange script.

 

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


//Type appropriate comment here, and begin script below
var id = g_form.getValue('staff_name'); //get user name from order guide form
var grUser = new GlideRecord('sys_user');
grUser.get('sys_id',id);



//set variable values in order guide
if(grUser.get(newValue)) {
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
}
}

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.

Thanks that has worked. I really appreciate that. Out of interest what is the reason a glide record is not good practice to use in a Client Script?

 

Thanks for your help,

 

Matt