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

Joe Wilmoth
ServiceNow Employee
ServiceNow Employee

Hi Jared,



You aren't able to access 'gs' from the Client. However, you could create a Script Include with a static method (put this logic in that method) and mark the Script Include to be client callable, and then use a client script to call the Script Include to retrieve this information.



Thanks,


Joe


I have never done any of that before. can you point me in the right direction or elaborate a little bit more?


Hi Jared,



Yes, please review our Wiki for more information on how to use Script Includes. I have attached a link below.



http://wiki.servicenow.com/index.php?title=Script_Includes



Thanks,


Joe


Probably doing it way wrong but here is what I did and it isn't working... As if Javascript wasn't finicky enough.. ServiceNow added a whole other level of complexity and ridiculousness.... This is should be a very very simple task but you have to jump through hoops to get it to work right..




Script Inclide:



var CompanyInclude = Class.create();



CompanyInclude.prototype = {


    initialize : function() {


    },



    myFunction : function() {


          gs.getUser().getRecord().getValue('company')


    },



    type : 'CompanyInclude'


};



Client Script Condition:




CompanyInclude != '5c6faa8389a249405f2c0203c80f605c'