How to use a client script if a field is not present in the form?

Rain Vaine
Kilo Sage

Hello experts,
I tried creating an onLoad client script that would give an error message if a user in the caller field is inactive. 

RainVaine_0-1675744238061.png

 

It is working fine with my default view since the caller field is present in my default view form. But it is not working on my custom view, wherein the caller field is remove in the form layout.

RainVaine_1-1675744312668.png


Do we have any of you have any idea of a way to make a client script work if the field is not present or visible in the form? Thanks.


Regards,
Vaine

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

The client script can only access the data that appears client side on your form, so if the caller field isn't there you'll need to pass data to the client script. In your use case, that's probably a display business business rule. A display business rule runs server side on form load and allows you to write data to the scratchpad. You can then access that data from the scratchpad in the client script and show your field message.

Here's our documentation on display business rules, and I bet there are some pretty good examples on how they're used out in the community.

View solution in original post

2 REPLIES 2

Brad Tilton
ServiceNow Employee
ServiceNow Employee

The client script can only access the data that appears client side on your form, so if the caller field isn't there you'll need to pass data to the client script. In your use case, that's probably a display business business rule. A display business rule runs server side on form load and allows you to write data to the scratchpad. You can then access that data from the scratchpad in the client script and show your field message.

Here's our documentation on display business rules, and I bet there are some pretty good examples on how they're used out in the community.

Hello, 
Yes thanks for the reply. I also found out this solution through trial and error. I found that it is possible via display business rule using g_scratchpad. But is it the correct behavior that this is not possible to execute in glideAjax. I also tried experimenting on GlideAjax and it did not work. Is that the supposed behavior in GlideAjax approach?

Regards,

vaine.