How to get view name from the portal using client script ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 07:22 AM - edited 09-18-2024 07:24 AM
Hi All,
I am opening Preapproved change request from the portal. I have written the Onchange client script on 'planned start date' field where I want capture the name of the view name from below url which should only work when Preapproved change request is opened. There are few suggestions to use "var view = getView()" but I can see the java browser error saying "its not defined"
How I could get the view name from below url or put such a constraint in client script so that defined code only should work when Preapproved change request is selected ?
Portal url :
https://demotest.service-now.com/change?id=preapproved_form&table=change_request&sys_id=-1&view=sip_preapproved&spa=1
Thanks,
Virendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 08:14 AM - edited 09-18-2024 08:27 AM
Hi I believe the following code should help. You can write this code on onLoad client script.
Mark as helpful if this solves your issue

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 08:35 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 09:08 AM
I have found the answer for this(link is given below).
https://servicenowguru.com/client-scripts-scripting/parse-url-parameters-client-script/
We can use fetch the parameter from the url using below code.
//call /place below 2 lines in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 11:09 AM - edited 09-18-2024 11:09 AM
This is one of the ways of doin it by manually parsing the string. Try this once I think this will work on portal