- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2018 07:51 AM
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:
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:
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2018 07:40 AM
(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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2018 05:10 AM
gs.getUser pull the logged in user. I think you need to current.user that will pull the user from the record that triggered the business rule when they were inserted into the group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2018 05:20 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2018 07:06 AM
I'm note sure you are using the setPreference correctly. It does not look like it set a user preference. I think you best bet would be to do the following code in your business rule.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var preference = new GlideRecord ('sys_user_preference');
preference.initialize(); //you may or may not need this
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2018 07:36 AM
Thanks for this.
It is now working.
I have thought thought of an issue. if we add a user to the group, then they get removed and at a later stage re-added it would create another user preference.
how can I check if a user preference exists, and if it does just update the value to 'comments', if it does not create the user preference?
Thanks
Sam

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2018 07:40 AM
(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);