I cannot set reference field modal window to read-only in Employee Center

jordimsant
Tera Guru

My team and I are developing some catalog items in our instance and we have noticed that the information icon in reference fields on the employee center opens an editable modal window as seen in the images (first one opens the second):

jordimsant_0-1757063744391.png

jordimsant_1-1757063777377.png

We would like this icon to appear and to show the information, but we would also like it to be read-only. How can we do this?

 

Thanks for everything!

 

4 REPLIES 4

Rafael Batistot
Tera Sage

Hi @jordimsant 

 

May you try via UI policy or catalog script to set read-only 

 

g_form.setReadOnly(<field_name>, true)

Do you mean that for the catalog item, we set all the fields from the referred table to be read only? Wouldn't this force us to repeat this client script for every reference field in every catalog item?

@jordimsant 

it's depends... if you have many catalogs with different variables that you need set read-only,  yes, will be necessary create one by one

Now, if the variables are the same but different catalogs, is possible create a script include 

setReadOnlyVariables: function(g_form, varList) {
        if (!varList || varList.length === 0)
            return;

        for (var i = 0; i < varList.length; i++) {
                g_form.setReadOnly(varList[i], true);
            } 
        }
    },


in or catalago client script > onLoad

function onLoad() {
    var variables = ['opt1', 'opt2', 'opt3']; // variables name
    var utils = new CatalogUtils();
    utils.setReadOnlyVariables(g_form, variables);
}



Ankur Bawiskar
Tera Patron
Tera Patron

@jordimsant 

are you checking with admin or non-admin?

If non-admin then did you check if that user has write access to that table?

if yes then it will allow user to edit

If you want to make it readonly for all then this link has solution

Make record preview readonly in Service Portal (all records) 

Another way to make entire form readonly when somebody clicks Preview is

1) create onLoad client script on that table being referred and use this logic

function onLoad() {
   //Type appropriate comment here, and begin script below
   if(top.location.href.indexOf('sc_cat_item') > -1){
	g_form.getFieldNames().forEach(function(field){
		//g_form.setMandatory(field , false);
		g_form.setReadOnly(field, true);
	});
   }
}

AnkurBawiskar_1-1757066895622.png

 

I just did this and it worked, this is another approach, it does show Save button but none of the fields are editable

Output:

AnkurBawiskar_0-1757066814654.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader