- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 05:35 AM
Hi there. I have the following requirement: On the cmdb_ci_computer table I have added a new List field called u_users which references the sys_user table. When assigned_to (also references sys_user) changes I want to copy the value to the u_users field, however, I don't want to replace the existing value but rather add to it. What I'll eventually have is a list of users who have been recorded to have used a computer. I also don't want duplicates adding but I figure SN might sort this for me automatically. Any thoughts? This is my current effort:
When: before (Insert and Update)
Condition: [Assigned to] [changes]
(function executeRule(current, previous /*null when async*/) {
current.u_users = current.assigned_to;
})(current, previous);
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 05:39 AM
UPDATED to filter out duplicates.
I would capture what's already in the field, then add the new person.
Something like this...
(function executeRule(current, previous /*null when async*/) {
var users = current.u_users.split(',');
users.push(current.assigned_to.toString());
users = new ArrayUtil().unique(users);
current.u_users = users.toString();
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 05:39 AM
UPDATED to filter out duplicates.
I would capture what's already in the field, then add the new person.
Something like this...
(function executeRule(current, previous /*null when async*/) {
var users = current.u_users.split(',');
users.push(current.assigned_to.toString());
users = new ArrayUtil().unique(users);
current.u_users = users.toString();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 06:01 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 06:03 AM
When I tried it out in my instance, it worked just fine without duplicates.
Can you paste the code you tried? The use of '.toString()' was incredibly important here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 06:24 AM
Thanks! I missed your update before I tried the code. Having added the updated code it works perfectly! Thank you so much, that's really really helpful. All the best my friend.