- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2020 04:20 AM
Hi, I need some help with setting a field from an array. My below business rule runs on an m2m table and updates the OIM entitlements field when any values are added to the related list table. However, I need some script for the if current.operation() == delete part. Can anyone help?
Here is an example, I have added 6 entitlements and it's updated the OIM entitlements field with the sys_id's. However, if they are removed, I need to update OIM entitlements field with new values (possibly push new values to an array?)
(function executeRule(current, previous /*null when async*/ ) {
var m2moim = new GlideRecord('x_lbg_insider_risk_insider_access_lookup');
m2moim.addQuery('sys_id', current.ir_access_categorisation);
m2moim.query();
if (current.operation() == 'insert') {
while (m2moim.next()) {
var entList = [];
var m2Gr = new GlideRecord('x_lbg_insider_risk_m2m_catalog_acce_ir_access_ca');
m2Gr.addQuery('ir_access_categorisation.sys_id', m2moim.sys_id);
m2Gr.query();
}
while (m2Gr.next()) {
entList.push(m2Gr.getValue('sys_id'));
m2moim.u_oim_entitlements = entList.join(',');
m2moim.updateMultiple();
}
} else if (current.operation() == 'delete') {
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2020 07:55 AM
Hi,
I just modified the code, just give a try,
(function executeRule(current, previous /*null when async*/ ) {
var m2moim = new GlideRecord('x_lbg_insider_risk_insider_access_lookup');
m2moim.addQuery('sys_id', current.ir_access_categorisation);
m2moim.query();
if (current.operation() == 'insert') {
var entList = [];
while (m2moim.next()) {
var m2Gr = new GlideRecord('x_lbg_insider_risk_m2m_catalog_acce_ir_access_ca');
m2Gr.addQuery('ir_access_categorisation.sys_id', m2moim.sys_id);
m2Gr.query();
while (m2Gr.next()) {
entList.push(m2Gr.getValue('sys_id'));
}
m2moim.u_oim_entitlements = entList.join(',');
m2moim.updateMultiple();
}
} else if (current.operation() == 'delete') {
var entList1 = [];
while (m2moim.next()) {
var m2Gr1 = new GlideRecord('x_lbg_insider_risk_m2m_catalog_acce_ir_access_ca');
m2Gr1.addQuery('ir_access_categorisation.sys_id', m2moim.sys_id);
m2Gr1.query();
while (m2Gr1.next()) {
entList1.push(m2Gr1.getValue('sys_id'));
}
m2moim.u_oim_entitlements = entList1.join(',');
m2moim.updateMultiple();
}
}
})(current, previous);
Regards,
Bala T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2020 07:58 AM
Bala, thank you so much. I have been stuck on this for days!