Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Make record preview readonly in Service Portal (all records)

kim-lindgren
Kilo Sage

Hi all,

 

When you have a form in Service Portal with a reference variable, whenever you click the (i) icon next to the field, you get a preview of the record. I don't want anyone to be able to edit what appears in the record preview, not even admin.

kimlindgren_0-1715587064188.png

How can I accomplish this? I have been looking at two different solutions so far, neither of them have done anything for me:

https://www.servicenow.com/community/developer-forum/make-preview-page-in-csm-portal-reference-field...(This one is about CSM Portal so maybe that's why it doesn't work)

https://www.servicenow.com/community/developer-forum/make-records-read-only-in-service-portal-copy-o...(This one looked promising but does nothing)

 

To complicate matters, I want this to apply to all records. So either I need a global ACL (but only for Service Portal) or client script or UI policy that sets readonly for all of these different records. For the first solution above, I tried applying a readonly UI policy to the table item_option_new, but I'm not even sure that is the correct one.

 

All help much appreciated!

 

Kim 

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hey,

If you don't fancy messing around with AngularJS you can add a global onLoad client script with the UI Type set to 'service portal' with the below script. 

 

function onLoad() {

	if(typeof g_modal == 'undefined')
	return;

	if(typeof this.jQuery == 'undefined')
	return;

	if(!this.jQuery('#widget-form'))
	return;

	var pModal = this.jQuery('#widget-form').parents('.modal');

	if(!(pModal instanceof this.jQuery) || pModal.length == 0)
	return;

	g_form.getFieldNames().forEach(function(field){
		//g_form.setMandatory(field , false);
		g_form.setReadOnly(field, true);
	});
}

 

Note: g_form.setReadOnly is only a visual deterrent, a user could be savvy enough to modify a field to allow editing and save to the db

View solution in original post

10 REPLIES 10

kim-lindgren
Kilo Sage

You are right, don't know why it was only reference fields at first. All fields on all tables are locked down now when opened in SP popup view.

 

Marking your initial reply as solution. Thanks a lot!