- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 01:06 AM
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.
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 03:22 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 03:22 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 01:19 AM
Hey Kieran,
Thanks a lot, didn't notice I had a reply here. Will test your solution and accept as solution if it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 01:34 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 02:33 AM
See below, the client script needs to match what is specified, and then second image shows the resulting manipulation of the service portal view