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

9 REPLIES 9

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

Hey Kieran,

 

Thanks a lot, didn't notice I had a reply here. Will test your solution and accept as solution if it works.

Sorry to say, this doesn't appear to do anything. The client script is onLoad, the UI Type is Mobile / Service Portal, script is set to active etc. I tested with both Table set to -None- and Table set to one particular table, but neither did anything (I do need it to run on all tables so I guess it should be -None-). Even tested setting UI Type to All, and it still doesn't do anything.

 

/Kim

See below, the client script needs to match what is specified, and then second image shows the resulting manipulation of the service portal view

KieranAnson_0-1716370354626.png