Programmatically setting user preferences, which are being ignored.

geoffcox
Giga Guru

I have a requirement for a UI action to toggle back and forth between views of the Incident form. It's easy enough to redirect the user to a particular view, but the user interface is not remembering the setting as the user's preferred view. So I programmatically insert records into the user preference table, but the system is ignoring these preferences, until I logout and log back in. Are the user preferences also being maintained in the session data somehow?

1 ACCEPTED SOLUTION

Slava Savitsky
Giga Sage

Syntax for client-side scripts is almost the same but without the gs,getUser() part:



setPreference('user_preference_name', 'user_preference_value');


View solution in original post

10 REPLIES 10

Slava Savitsky
Giga Sage

Are you inserting/updating preferences using a usual GlideRecord query or using setPreference method? I think the preferences are not applied if changed using a GlideRecord query.


Thanks Slava, I thought you were really onto something! But I tried the following with no effect:



gs.getUser.setPreference('incident.view','tier_3');


gs.getUser.setPreference('incident_list.view','tier_3');



I couldn't find the setPreference() method documented on the wiki, except for how it applies to the UI Page object. Are you aware of any documentation for it?


In your examples, there are no brackets after getUser. Can it be the reason why the method is not working?


No, that was a typo in my response. It was actually:



current.update();
gs.getUser().setPreference('incident.view','tier_3');
gs.getuser().setPreference('incident_list.view','tier_3');
action.setRedirectURL('incident.do?sys_id=' + current.sys_id + '&sysparm_view=tier_3');