setPreference method not working on action script.

Ivar Donado
Mega Sage

I've been working on a scoped application that redirects users based on the form view. I need to somehow reset the form view after that so the next time the user signs in the view is back to default.

I tried just using gs.getUser().setPreference('x_bonm_bip_data_policy_term.view', 'default') and gs.getUser().setPreference('x_bonm_bip_data_policy_term.view', '') in background script and both worked, however if I use them on a Script Action triggering from the session.established event (which happens when the user signs in) they simply don't work.

I have tested with logs and the script action is actually being triggered, but that setPreference does nothing. Any idea why might this be happening?

1 ACCEPTED SOLUTION

Namrata Khabale
Giga Guru

Hey Ivar Donado,

Refer the thread it might help you:

https://community.servicenow.com/community?id=community_question&sys_id=7b80e99fdbc66784656a5583ca96...

 

And also go through the link:

http://www.john-james-andersen.com/blog/service-now/servicenow-user-preferences-server-client-access...

 

Mark Correct and Helpful on the basis of Impact!!!

 

Best Regards,

Namrata.

View solution in original post

4 REPLIES 4

Tony Chatfield1
Kilo Patron

Hi, the docs only show entries for clientSide
https://developer.servicenow.com/dev.do#!/search/madrid/All/setPreference

and it may be that serverSide setPreference is only available in global scope?

You might be able to work around it with a glidequery lookup\update to set your values directly on sys_user_preference table.

I thought so after making this question. I tried doing a query and...weirdly enough I can't even get the record count (.getRowCount()) from the action script, but I do get it from the background script. This looks more like an access issue from the action script to the user preferences table.

Namrata Khabale
Giga Guru

Hey Ivar Donado,

Refer the thread it might help you:

https://community.servicenow.com/community?id=community_question&sys_id=7b80e99fdbc66784656a5583ca96...

 

And also go through the link:

http://www.john-james-andersen.com/blog/service-now/servicenow-user-preferences-server-client-access...

 

Mark Correct and Helpful on the basis of Impact!!!

 

Best Regards,

Namrata.

I had attempted to use those methods (using the user id). And even tried a query through gliderecord just to check if I could delete or modify the preference records but I can't even get the amount of records found with getRowCount() there (it always returns zero). I assume there's some kind of access restriction to the preferences table from action scripts as every script I come up with works when run as background script.