- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2014 08:52 AM
I am trying to set a condition on a client script so it will run for all users except for those with a specific company value set on their user account... and I cannot figure out what I am doing wrong!
Condition:
gs.getUser().getRecord().getValue('company') != 'CompanySysID'
Any Suggestions??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2014 08:51 AM
I would move the condition into the script itself:
if (g_scratchpad.userCompany.... (ps you had a typo in the screenshot example condtion, so fixing that might just work).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2014 10:04 AM
Your script include needs to return a value.
return gs.getUser().getRecord().getValue('company');
Then in your client script you need to get the script include and call the function.
var func = new CompanyInclude();
var company = func.myFunction();
as you are testing use Alert statements or one of the other messaging options to check to see if you are getting back the value you expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2014 09:47 AM
You could also create an on display business rule that puts the users company into the scratchpad and access the value from the client script.
In the BR:
g_scratchpad.userCompany = gs.getUser().getRecord().getValue('company');
In Client Script
if(g_scrachpad.userCompany != 'CompanySysID'){
}
Client Script Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2014 01:17 PM
How do I need to setup the business rule? before - insert? Client callable?
Also, would I need to add the code you mentioned into the client script itself? Or can I put it in the condition line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2014 01:25 PM
The business rule's When: Display
Yes you can get the scratchpad value in the client script's condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2014 08:41 AM