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

Brian Lancaster
Tera Sage

I would do a business rule on the sys_user_grmember that runs when a record is inserted and the group matches the one you are talking about.  You can then script it to add a record into sys_user_preference table.

Hi,

 

I've attempted to create a business rule, but I'm struggling to get this to work - still learning scripting.

currently have my business rule set as:

find_real_file.png

find_real_file.png

 

I've added 3 users to the group Customer portal - Report Users, but no preference has been set for these.

Can you point me in the right direction?

Thanks

Hi,

 

I've noticed that I am updating my own preference rather than the user being added to the group,

What do I need to do to get the user being added to the group?

Thanks

Sam

I've just re-tried but still not getting the user preference set:

 

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

	var userGR = new GlideRecord('sys_user');
	if(userGR.get(current.getValue('user'))){
	gs.log('username - ' + userGR);
	userGR.setPreference("glide.ui.incident.stream_input", "comments");
	}
})(current, previous);

in my logs I can see:

find_real_file.png

I've checked and the sys ID is the user I've added to the group