- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 04:55 AM
Hi Team,
In the form on Native view have created a button which leads to workspace to the same record. I require the form to be read only in native view but should be editable in workspace view.
Please let me know How can we achieve This.
Thank you.
Solved! Go to Solution.
- 1,239 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 11:32 PM - edited ‎05-31-2023 11:37 PM
I have used the Below Code and its working fine.
function onLoad() {
//Type appropriate comment here, and begin script below
var url = top.location.href; // getting the URL Link
var pathname = new URL(url).pathname; // getting the Path workspace : now/risk/, Native :now/nav/ui/.
pathname = pathname.split('/');
var ur = pathname[2];// getting if its a workspace or native
if ( ur == 'nav') {
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
}else{
fields = g_form.getEditableFields();
for ( x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], false);
}
}
}
Regards,
Prajwal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 04:59 AM
You can check below thread to check if you are in workspace or not, then based on that write script to make your form field readonly.
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 05:01 AM
you can use onLoad client script and check the view and use this script to make all fields readonly
function onLoad(){
if(g_form.getView() != 'workspace'){
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 11:27 PM
Hi @Ankur Bawiskar,
Thank you for your response. g_form.getView() is giving undefined. But thank you for providing an idea.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 11:29 PM
it should give the view name when the client script runs in workspace view
what did you debug?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader