
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 05:50 AM
Hi folks,
I have two list type fields on a form both are referenced from other tables.
I need to populate u_enterprise_app_definition.managed_by on to the Custom manged by field on change or update of Enterprise app definition field.
I have written the before business rule but dot walking is not working for list type fields. Can anyone give me the solution.
eg: current.u_custom_manged_by = current.u_enterprise_app_definition.managed_by; (but this is not working as the field type is list)
Thanks
Sumanth
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 07:46 AM
Code snippet you can try:
var managers = [];
if (!gs.nil(current.u_enterprise_app_definition)) {
var enterpriseAppDefinition = new GlideRecord('u_cmdb_ci_appl_enterprise');
enterpriseAppDefinition.addQuery('sys_id', 'IN', current.getValue('u_enterprise_app_definition'));
enterpriseAppDefinition.query();
while (enterpriseAppDefinition.next()) {
managers.push(enterpriseAppDefinition.getValue('managed_by'));
}
// Remove duplicates
var arrayUtil = new ArrayUtil();
managers = arrayUtil.unique(managers);
}
current.u_custom_manged_by = managers.join(',');
Just make sure you execute BR also when the value of Enterprise App Definition is empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 06:01 AM
Hi Sumanth,
List field type will give you comma separated sys_ids of referenced records. So you need to build a query to the referenced table using "sys_id" "IN" <list-of-sys_ids> to get all the referenced records, iterate through them and add the dot-walked value to the result.
var managers = [];
var enterpriseAppDefinition = new GlideRecord('name-of-reference-table');
enterpriseAppDefinition.addQuery('sys_id', 'IN', current.getValue('u_enterprise_app_definition'));
enterpriseAppDefinition.query();
while (enterpriseAppDefinition.next()) {
managers.push(enterpriseAppDefinition.getValue('managed_by'));
}
current.u_custom_managed_by = managers.join(',');
I did not test the code at all so please test it a lot :-). Also you might want to improve the logic to make sure every user is involved only once as manager in case two enterprise applications have same manager.
Best regards,
Dominik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 06:08 AM
Thank you Dominik.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 07:03 AM
Hi Dominik,
Yes as you said in case two enterprise applications have same manager the Custom Managed By field is filling with two values(duplicates).
If enterprise applications value is removed the managed by value is not getting removed.
Your suggestion please?
Thanks
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 07:22 AM
To make list of managers unique, use ArrayUtil's unique method documented here: https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...
Regarding the removal of manager, if the code I share is within onBefore business rule that is executed any time the Enterprise App Definition value is changed, I guess the manager list should be updated as well. If this is not the case, please share your business rule definition and the code you are using at the end.
Best regards,
Dominik