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

How to pass server-side information to a form?

k0a1a
Kilo Expert

Hi all,

what's the easiest way to pass (embed / force) server-side information into a Glide form?

The background of the question is,

I want to enable/disable a control in the form sys_user_grmember depending on the type of the group. (Group type is notoriously a list of records in table Group Type).

Best if I don't have to operate with type sys_id but rather with type name.

Querying this information on the client side is a nightmare, I have to find out first sys_id of the group type in question, then get reference to the group (remember, we are in sys_user_grmember so group.type is not available straight away), and finally enable/disable my control based on the list search result.

It feels somehow complex. I'd rather force some data into the form at the server side, before the form gets loaded, and then just use this data in the form directly, without roundtrip to the server.

Thank you!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

If the server information is NOT dependent on changing information on the client (e.g. push it once and forget it) then your best bet is with the g_scratchpad object. Set the properties in a display business rule, then the client script has access to the same properties.



Docs: Client Scripts


Client Script Best Practices - ServiceNow Wiki      


View solution in original post

6 REPLIES 6

Chuck Tomasi
Tera Patron

If the server information is NOT dependent on changing information on the client (e.g. push it once and forget it) then your best bet is with the g_scratchpad object. Set the properties in a display business rule, then the client script has access to the same properties.



Docs: Client Scripts


Client Script Best Practices - ServiceNow Wiki      


davidgilmore
Tera Contributor

Use an onDisplay business rule and pass a value to the scratchpad, you don't need to store anything on the form


k0a1a
Kilo Expert

Thanks mates, looks like it's the only way, although I don't really feel comfortable... adding code to every query to a table... you know what I mean.


Waiting for a while, perhaps yet another approach comes up.


sunmalar
Tera Contributor

hope this can help



in client Script:


var grp = g_form.getReference('group');


      //alert("BS: "+BS.u_documentation);


              if( grp != undefined )


              {


              if(grp.grouptype == 'primary')


              {


                      //enable/disable your control ;


              }