modify system property with script action

will_smith
Mega Guru

Hi ServiceNow community!

I have set up a script action to modify the system property "collaboration.frameset", but am running into an issue where the system property is not updating upon logging in with a test user who has no roles. Can someone help me debug this?

have used this same method previously to modify a user preference and was hoping to do the same to scriptomagically disable the property with a role-based condition.

Thanks for taking a look at this for me.

Below is my script action...

find_real_file.png

1 ACCEPTED SOLUTION

will_smith
Mega Guru

Could it be that the ACL's are restricting access to the system properties for the user, therefore they cannot update the value?


View solution in original post

7 REPLIES 7

will_smith
Mega Guru

Also, I just built a quick fix script to test this and this returns "true" then "false". Is it possible to adapt this for use in my script action?



var gr = new GlideRecord('sys_properties');


gr.addActiveQuery();


gr.addQuery('name','collaboration.frameset');


gr.query();




if (gr.next()) {


  var user = new GlideRecord('sys_user_has_role');


  user.addActiveQuery();


  user.addQuery('user_name','Test.User');


  gs.print('System Property: ' + gr.name + ' has a value of ' + gr.value);


  if (user.gs.hasRoles != 'itil') {


  gr.value = "false";


  }


  gs.print('System Property: ' + gr.name + ' has a value of ' + gr.value);



}


Nick65
Mega Expert

When updating a value in any table in SN you need to run the update() method once you query for the correct record.   So,


var gr = new GlideRecord('sys_properties');


gr.addActiveQuery();


gr.addQuery('name','collaboration.frameset');


gr.query();




if (gr.next()) {


gr.value = false;


//gr.setWorkflow(false); //this will prevent business rules from running, if required


gr.update();


}



Remember almost everything in SN is a table. Always be aware of onUpdate business rules that may run because of this.


will_smith
Mega Guru

Thanks Nick. I combined our scripts and when I log in as a test user who has no roles I still see the Connect and presence indicators, which tells me the script action didn't work... other thoughts?



var gr = new GlideRecord('sys_properties');


gr.addActiveQuery();


gr.addQuery('name','collaboration.frameset');


gr.query();



if (gr.next()) {


var user = new GlideRecord('sys_user_has_role');


user.addActiveQuery();


user.addQuery('user_name',gs.getUser());


if (user.gs.hasRoles != 'itil') {


gr.value = "false";


gr.setWorkflow(false); //this will prevent business rules from running, if required


gr.update();


}



}


will_smith
Mega Guru

Could it be that the ACL's are restricting access to the system properties for the user, therefore they cannot update the value?