Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Using setPreference to set system

Brendan Hallida
Kilo Guru

Hi all,

With the holidays upon us, I am using the downtime to automate some of the more tedious tasks.   I am currently working on the after clone work, as this is something I had previously neglected and grinded.

On our Dev instance, we have a specific theme which I would like to script to be set to default after the clone.

I have found the following function, which works well and sets my user preference to 'test'.

gs.getUser().setPreference("glide.css.theme.ui16", "test");

What I would like to do, is set the system property.

find_real_file.png

Are we able to do this with Java Script?

Cheers,

Brendan

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

Write a System Clone Cleanup Script to


  • Delete all existing preferences
  • Create a system level preference for your DEV theme


//Delete all user preferences


var grUserPreference = new GlideRecord('sys_user_preference');


grUserPreference.addQuery('name','glide.css.theme.ui16');


grUserPreference.addQuery('system',false);


grUserPreference.deleteMultiple();



//Set system wide user preference


grUserPreference = new GlideRecord('sys_user_preference');


grUserPreference.addQuery('name','glide.css.theme.ui16');


grUserPreference.addQuery('system',true);


grUserPreference.query();


if( grUserPreference.next() ) {


      grUserPreference.value = 'test';


      grUserPreference.update();


}



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

2 REPLIES 2

The SN Nerd
Giga Sage
Giga Sage

Write a System Clone Cleanup Script to


  • Delete all existing preferences
  • Create a system level preference for your DEV theme


//Delete all user preferences


var grUserPreference = new GlideRecord('sys_user_preference');


grUserPreference.addQuery('name','glide.css.theme.ui16');


grUserPreference.addQuery('system',false);


grUserPreference.deleteMultiple();



//Set system wide user preference


grUserPreference = new GlideRecord('sys_user_preference');


grUserPreference.addQuery('name','glide.css.theme.ui16');


grUserPreference.addQuery('system',true);


grUserPreference.query();


if( grUserPreference.next() ) {


      grUserPreference.value = 'test';


      grUserPreference.update();


}



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Hiya Paul,



Wow, thanks for that.   Works a treat with the background scripts, so i'm confident it will work



Cheers,


Brendan