Write a client script using GlideUser API to set default field values based on user preferences.

SK00335601
Tera Contributor

I am new to servicenow. Can anybody please tell what is expected in question - Write a client script using GlideUser API to set default field values based on user preferences. and any hint for it?

9 REPLIES 9

Ramkumar Thanga
Mega Sage

Okay,

I don't think that is possible via the GlideUser API .

GlideUserAPI is much limited.

You can proceed with a GlideAjax call from the client script to query the sys_user_preference table.

 

Thanks!

Ram

thomaskennedy
Tera Guru

It's not obvious to me how the user's preferences could be exposed to a client script. I see nothing about this in the GlideUser api. Perhaps the user preferences could be read server-side in a business rule (there's a table where these preferences are stored) and inserted using putClientData, and retrieved later, on the client side, using getClientData.

SK00335601
Tera Contributor

Ok. Thanks Ramkumar and Thomas Kennedy. I will check .

 

in a business rule

 

A business rule has four "when" settings: before, after, async and display. That last one can be used to sneak values down to the client side without the use of GlideAjax. It would be roughly as follows:

 

In the business rule (that is, server side), use GlideSession.putClientData()

In the client script, retrieve those values using GlideUser.getClientData()

 

I believe you are still allowed to use GlideRecord on the client side to fetch user preferences from whatever-that-table-is, but this is slow. (There is, or was, some magic in that class that lets it make remote calls back to the tenant when run from the client side.) GlideAjax would work, but it's more complex to set up.

 

I do not know of an out-of-box method for getting user preferences client-side, without using one of the above options.

Thanks Thomas. !!