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

I see only one attached image.

 

Okay, I see now that your solution actually locked down all reference field on the record preview. Which part of your jQuery conditions should I change if I want to lock down *all* fields on the preview? (This is what I wanted, but perhaps I wasn't very clear.)

 

I could play around with it of course but I don't honestly understand what these conditions do... I need to ensure that the solution is solid and doesn't have any bad side-effects.  

Hi Kim,

The script marks all fields within the form modal popup as read only, it doesn't discriminate against field type. This is shown by the "email" field in my screenshot for the sys_user record being read only

hey @Kieran Anson

I hope the above solution worked for Kim. Much appreciated!

I was looking into whether it’s possible to make reference variable values copyable in Service Portal.

Requirement: I need to enable users to copy the value displayed in reference variables on the CSM Portal. Do you have any idea how we can achieve this functionality?

Any suggestions or guidance would be greatly appreciated.

Thanks!

Anil9866_0-1788352031726.png