Set user preference when user added to a group

Sam Ogden
Tera Guru

Hi All,

We are in the process of adding a dashboard to our customer portal.  This shows various reports about that customers incidents.  When a portal user drills into the incident they get the self-service view of the form.

On our incident form we have both work notes and additional comments fields on the form.  There is a tick box which alters which is displayed:

find_real_file.png

We have a system preference that sets this to worknotes - this is in place as a safe guard to try and prevent users accidentally adding a work note as an additional comment.

As portal users do not have visibility of work notes it is meaning that the user sees the 'post' button but there is no field to input the comment:

find_real_file.png

If I create as user preference for the portal user of glide.ui.incident.stream and set this to comments it then works and the portal user gets the field to add additional comments.

I don't want to have to add this user preference manually everytime we give a user access to the dashboard.  We control this by adding the users to a specific group.  Is there a way to get the user preference to auto generate when the user is added to the group?

Are there any other altrnatives

Thanks

Sam

1 ACCEPTED SOLUTION

(function executeRule(current, previous /*null when async*/) {


// Add your code here
var preference = new GlideRecord ('sys_user_preference');
preference.addQuery('name','glide.ui.incident.stream_input');
preference.addQuery('user', current.user);
preference.query();
if (!preference.next()){
preference.name = 'glide.ui.incident.stream_input';
preference.vaule = 'comments';
preference.type = 'string';
preference.user = current.user;
preference.insert(); //since you said this was a before business fule you should not need this but I wanted to give it to you just in case.
}

})(current, previous);

View solution in original post

12 REPLIES 12

This is what I have attempted:

(function executeRule(current, previous /*null when async*/) {
	
	var repuser = current.user.sys_id;
	gs.log('username - ' + repuser);
	
	var preference = new GlideRecord ('sys_user_preference');
	preference.addQuery('user', repuser);
	preference.addQuery('name', 'glide.ui.incident.stream_input');
	preference.query();
	if(preference.next){
		gs.log('hit if statement');
		preference.value = 'comments';
		preference.update();
		}
		else {
			gs.log('hit else statement');
		preference.initialize(); //you may or may not need this
		preference.name = 'glide.ui.incident.stream_input';
		preference.value = 'comments';
		preference.type = 'string';
		preference.user = current.user;
		preference.insert(); //since you said this was a before business fule you should not need this but I wanted to give it to you just in case.
		}
})(current, previous);

 

If no user preference exists then it creates one as I expect.  If the preference exists, instead of updating the current user preference it is creating a new preference with just the value being set as comments.

I can tell that it is being found and going into the 'if' statement with my log, but it is creating a new preference where i want it top update the preference that it has found. 

If the preference already exists why would it need to updated?  The code I gave you will only create it if it does not exit.

no problem, I thought I had a test where it was duplicating the preference, but reverted rule back and can't replicate.

Happy to leave as is 

Thanks for all your help.