- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 01:54 AM
Hi,
I am trying to make a client script with the condition View == self_service and if true I want to set the state to Active. Here's my code but it is not working. Do you have any other way to meet what I am trying to do?
function onLoad() {
//Type appropriate comment here, and begin script below
var view = getView();
if (view == 'self_service'){
g_form.setValue('state','2');
}
}
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 02:04 AM
- function onLoad() {
- //Type appropriate comment here, and begin script below
- var view = getView();
- if (view == 'ess'){ //self service view name is ess so make to ess
- g_form.setValue('state','2');
- }
- }
try this script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 02:13 AM
View name is not self_service rather its ess.
If you are not aware of the view name please print the view name and validate the same. For eg :- alert(view); This will give you the correct value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 02:17 AM
Hi Diane,
var strView = g_form.getParameter('view');
alert(strView);
Please try with this code it will help for you.
Regards,
Parvinder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 02:20 AM
Hi Diane,
First of all getView() is a Server side script which you can not use in the Client Script. You need to write the script like below. The script is untested but hope this will work. Also, please remember if you are dealing with 'Default' view, you must remember that the variable strView will return null.
For details, you might refer section 4.8.11 here: http://wiki.servicenow.com/index.php?title=Client_Scripts
function onLoad() {
var objView = document.getElementById('sysparm_view');
var strView = objView.getAttribute('value');
if (strView == 'ess') {
g_form.setValue('state','2');
}
}
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 12:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 02:24 AM
Below function will provide you with form view in client scripts
g_form.getViewName()