The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Condition on Client Script

jared_wentzel
Kilo Contributor

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??

1 ACCEPTED SOLUTION

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).


View solution in original post

13 REPLIES 13

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.


paul_mcnamara
Giga Expert

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


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.


The business rule's When: Display


Yes you can get the scratchpad value in the client script's condition


What am I doing wrong here??



Business Rule


buinessrule.JPG



Client Script




clientscript.JPG