Writing a Client Script for a Scoped Application

jmiskey
Kilo Sage

We have created a Desktop Services Table, which extends the Task table.

We have also created a user defined field on our User table named "legal hold", which is a True/False check box.

What we are trying to do is that when someone is entering information on the Desktop Services Form, when they fill out the End User field, if they choose someone who has the "legal hold" field set to True on their User record, it will return a message to the screen.

Also, we are trying to do this on Helsinki.

So, we first tried creating a Client Script in the Scoped Application, but that did not work.   My co-worker noticed that Helsinki allows from Cross Scripting between the Scoped Application and the Global Application, so he enabled that.   Then we tried to recreate the Client Script in the Global Application, but that did not see, to work either.   I am not if the problem is with my script (I am pretty new to ServiceNow), or with the fact that we are working with a Scoped Application.

Here is how we set up the Client Script:

Table: Desktop Services Table

UI Type: Desktop

Type: onChange

Field name: end_user

Script:

[code]

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {

          return;

    }

              //check for Legal Hold

              g_form.getReference('end_user',legalHoldUser);

             

              function legalHoldUser(endUser) {

                              if (endUser.u_legal_hold =='true') {

                                              g_form.showFieldMsg('end_user', 'User is on legal hold', 'info');

                              }

              }

             

}

[/code]

We tried similar code in both the Scoped and Global Applications, but they both returned errors which look like this when we try to populate the End User field:

onChange script error: TypeError: Object expected function(){var o=i(m,arguments);return l.apply(n,o)}

It appears that it is looking for a loop, but I am not sure why, as since we are using a Reference field, it should only be returning a single record.

Does anyone see anything that might be problematic, or can anyone provide guidance?

Thanks

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Joe,



I don't see any issues as getReference() should be supported within and without a scoped application.



ServiceNow Developers



If you disable your client script does the error go away? Possibly it's in another script.


View solution in original post

3 REPLIES 3

Michael Fry1
Kilo Patron

I noticed you have a function inside another function. Did you try ending the first one, so the second one can be called?


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Joe,



I don't see any issues as getReference() should be supported within and without a scoped application.



ServiceNow Developers



If you disable your client script does the error go away? Possibly it's in another script.


Brad,



That was it!   There was another Client Script that someone was testing against the same field that was returning the errors.   When I deactivated that other Client Script, mine worked perfectly!



Thanks for pointing me in the correct direction!