I want to set the user count on a field from custom table if the form update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2024 10:11 PM
Hi Expert,
I have a custom table name is "u_device" and on this table a field is "Number of user". If the form is updated the number/Count of user (it comes from asset table, Please see attched screenshot for filter and table) should be set on the field "Number of user".
User count details:
Table : alm_asset
Filter : model_category=81feb9c137101000deeabfc8bcbe5dc4^install_status=1^assigned_toISNOTEMPTY.
Note: some user's have 2 or more asset. so group by "assigned to".
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2024 11:53 PM
Hi @Chandra18 ,
You can try the below steps:
Write a Business rule on 'u_device' table
Advanced checkbox true
When to run: after update
In advanced section, write the below script:
(function executeRule(current, previous /*null when async*/ ) {
var getTotalCount = [];
var getUsers = new GlideAggregate('alm_asset');
getUsers.addEncodedQuery('model_category=81feb9c137101000deeabfc8bcbe5dc4^install_status=1^assigned_toISNOTEMPTY');
getUsers.addAggregate('COUNT', 'assigned_to');
getUsers.groupBy('assigned_to');
getUsers.query();
while (getUsers.next()) {
var aggCount = getUsers.getAggregate('COUNT', 'assigned_to');
getTotalCount.push(aggCount);
}
var currRec = new GlideRecord('u_device');
if (currRec.get(current.sys_id)) {
currRec.number_of_users = getTotalCount.length; //Update the field name(numbers_of_user) with the backend name of Number of user attribute
currRec.update();
}
})(current, previous);
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2024 02:49 AM - edited ‎07-01-2024 02:51 AM
Hi @SN_Learn ,
Thank you so much for your help!
If I want to Push user also and by the script include I want to use scripted filter for user and set/Show the count by business rule.
My mean I want to return user sys_id & Count of user both. Could you please provide the script include script & set the count by business rule.