- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 12:42 PM - edited 12-08-2023 01:02 PM
Hi All ,
I have a requirement where I am little stuck with scripting. Kindly need some guidance from experts .
We have a requirement where , there are number of groups if a user selects any of the groups from the list except that grp remaining should be proceeded for orchestration .
Comments added within script for better understanding .
//workflow.scratchpad.groupNames=workflow.scratchpad.grps;
workflow.scratchpad.restricted_groups = '';
//restrict few groups for orchestration -STRY0417475
var arrayGroups = workflow.scratchpad.grps;
//from here I am taking values from user selected from item
workflow.scratchpad.restricted_groups = arrayGroups.split(",");
gs.log(current.number + 'workflow.scratchpad.groupName' + workflow.scratchpad.restricted_groups);
var gr1 = new GlideRecord('sys_user_group');
//this is the list from from which if groups are there we have exclude those from orchestration
gr1.addEncodedQuery('nameLIKEROL-PCCG_CHS_MTL-ag-EBT_Net-V5^ORnameLIKEROL-PCCG_CHS_TOR-ag-EBT_Net-V5-RX^ORnameLIKEROL-PCCG_CHS_MTL-ag-EBT_Net_Admin-V5^ORnameLIKEROL-SSG-WF-SFTP-Users^ORnameLIKEROL-RPA-OFFICE-BOTS-ACCESS^ORnameLIKEROL-WF-PR-Development^ORnameLIKEROL-WF-PR-ADMIN^ORnameLIKEROL-WF-PR-ADMIN-EI^ORnameLIKEROL-WF-PR-Functional^ORnameLIKEROL-SSG-FORESCOUT^ORnameLIKERUN_NETWORK_NOC_CAN^ORnameLIKERUN_NETWORK_NOC_US_INTL^ORnameLIKERUN_NETWORKS_NOC_ESC^ORnameLIKEROL-ISS Admin^ORnameLIKEROL-ISS Operator^ORnameLIKEBMOUNICAGRP^ORnameLIKEBMOUNICAADM^ORnameLIKEADM-EPS-PE-BSM^ORnameLIKEROL-ISS^ORnameLIKEROL-MIDS Privacy^ORnameLIKEROL-PRODOPS-ACHDT^ORnameLIKEEI_BOWSS^ORnameLIKEROL - LEXMARK MARKVISION ACCESS^ORnameLIKEROL- EJM^ORnameLIKEROL-DevOpsToolsDT^ORnameLIKEROL-BMO-PR-27497-RDMP^ORnameLIKEROL-Basel_CAT_App^ORnameLIKEROL-Vignette BMO Canada^ORnameLIKEROL-SDE^ORnameLIKErol-forescout^ORnameLIKEROL-Centaur-RAF^ORnameLIKEROL-STBG^ORnameLIKEROL-IronPort');
gr1.query();
while (gr1.next()) {
var arr_groups_restrict = gr1.sys_id.toString();
gs.log(current.number + 'thiru 3' + arr_groups_restrict);
//here I am facing difficulty in removing the restricted group from user selected groups
for (var i = 0; i < workflow.scratchpad.restricted_groups.length; i++) {
if (workflow.scratchpad.restricted_groups.indexOf(arr_groups_restrict[i]) > -1) {
workflow.scratchpad.restricted_groups.replaceAll(arr_groups_restrict[i], '');
gs.log(current.number + 'array' + arr_groups_restrict[i]);
if (workflow.scratchpad.restricted_groups.indexOf(',,') > -1) {
workflow.scratchpad.restricted_groups.replaceAll(',,', ',');
}
}
workflow.scratchpad.groupNames = workflow.scratchpad.restricted_groups;
}
}
gs.log(current.number + 'resrtict groups thiru' + workflow.scratchpad.groupNames);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 10:06 AM - edited 12-12-2023 10:08 AM
It worked from the modified encoded query:
@AshishKM Thank you so much for the help 😊.
var gr1 = new GlideRecord('sys_user_group');
gr1.addEncodedQuery('sys_idIN' + restGroupArray + '^name!=ROL-PCCG_CHS_MTL-ag-EBT_Net-V5^name!=ROL-PCCG_CHS_TOR-ag-EBT_Net-V5-RX^name!=ROL-PCCG_CHS_MTL-ag-EBT_Net_Admin-V5^name!=ROL-SSG-WF-SFTP-Users^name!=ROL-RPA-OFFICE-BOTS-ACCESS^name!=ROL-WF-PR-Development^name!=ROL-WF-PR-ADMIN^name!=ROL-WF-PR-ADMIN-EI^name!=ROL-WF-PR-Functional^name!=ROL-SSG-FORESCOUT^name!=RUN_NETWORK_NOC_CAN^name!=RUN_NETWORK_NOC_US_INTL^name!=RUN_NETWORK_NOC_US_INTL^name!=ROL-ISS Admin^name!=ROL-ISS Operator^name!=BMOUNICAGRP^name!=BMOUNICAADM^nameNOT LIKEADM-EPS-PE-BSM^nameNOT LIKEROL-ISS^nameNOT LIKEROL-MIDS Privacy^nameNOT LIKEROL-PRODOPS-ACHDT^nameNOT LIKEEI_BOWSS^nameNOT LIKEROL - LEXMARK MARKVISION ACCESS^nameNOT LIKEROL- EJM^nameNOT LIKEROL-DevOpsToolsDT^nameNOT LIKEROL-BMO-PR-27497-RDMP^nameNOT LIKEROL-Basel_CAT_App^nameNOT LIKEROL-Vignette BMO Canada^nameNOT LIKEROL-SDE^nameNOT LIKErol-forescout^nameNOT LIKEROL-Centaur-RAF^nameNOT LIKEROL-STBG^nameNOT LIKEROL-IronPort');
gr1.query();
while (gr1.next()) {
workflow.scratchpad.groupNames = gr1.sys_id;
}
gs.log(current.number + 'Groups' + workflow.scratchpad.groupNames);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 03:27 PM
Hi @thirumala2 ,
Please review the logic again and focus on following point.
This scratchpad value is array and you used in for loop
workflow.scratchpad.restricted_groups = arrayGroups.split(",");
but this is inside the while loop and not an array , gr1 represent the single record for each iteration of while loop
var arr_groups_restrict = gr1.sys_id.toString();
if so the following if condition will not execute property
if (workflow.scratchpad.restricted_groups.indexOf(arr_groups_restrict[i]) > -1) {
as per my understanding, you are trying to remove groups from below arrayList based on matched, given in encoded query.
workflow.scratchpad.restricted_groups
Try the updated part from below code and test.
while (gr1.next()) {
var arr_groups_restrict = gr1.sys_id.toString();
workflow.scratchpad.restricted_groups.splice( workflow.scratchpad.restricted_groups.indexOf(arr_groups_restrict),1);
}
//after while loop cpmplete, set the groupNames ( which is actually sys_id )
workflow.scratchpad.groupNames = workflow.scratchpad.restricted_groups;
-Thanks,
AshishKMishra
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 04:28 PM
HI Ashish,
Thanks for the reply .
But its not working ,in logs it showing empty for that variable.
workflow.scratchpad.restricted_groups = '';
//restrict few groups for orchestration -STRY0417475
var arrayGroups = workflow.scratchpad.grps;
workflow.scratchpad.restricted_groups = arrayGroups.split(",");
gs.log(current.number + 'workflow.scratchpad.groupName' + workflow.scratchpad.restricted_groups);
var gr1 = new GlideRecord('sys_user_group');
gr1.addEncodedQuery('nameLIKEROL-PCCG_CHS_MTL-ag-EBT_Net-V5^ORnameLIKEROL-PCCG_CHS_TOR-ag-EBT_Net-V5-RX^ORnameLIKEROL-PCCG_CHS_MTL-ag-EBT_Net_Admin-V5^ORnameLIKEROL-SSG-WF-SFTP-Users^ORnameLIKEROL-RPA-OFFICE-BOTS-ACCESS^ORnameLIKEROL-WF-PR-Development^ORnameLIKEROL-WF-PR-ADMIN^ORnameLIKEROL-WF-PR-ADMIN-EI^ORnameLIKEROL-WF-PR-Functional^ORnameLIKEROL-SSG-FORESCOUT^ORnameLIKERUN_NETWORK_NOC_CAN^ORnameLIKERUN_NETWORK_NOC_US_INTL^ORnameLIKERUN_NETWORKS_NOC_ESC^ORnameLIKEROL-ISS Admin^ORnameLIKEROL-ISS Operator^ORnameLIKEBMOUNICAGRP^ORnameLIKEBMOUNICAADM^ORnameLIKEADM-EPS-PE-BSM^ORnameLIKEROL-ISS^ORnameLIKEROL-MIDS Privacy^ORnameLIKEROL-PRODOPS-ACHDT^ORnameLIKEEI_BOWSS^ORnameLIKEROL - LEXMARK MARKVISION ACCESS^ORnameLIKEROL- EJM^ORnameLIKEROL-DevOpsToolsDT^ORnameLIKEROL-BMO-PR-27497-RDMP^ORnameLIKEROL-Basel_CAT_App^ORnameLIKEROL-Vignette BMO Canada^ORnameLIKEROL-SDE^ORnameLIKErol-forescout^ORnameLIKEROL-Centaur-RAF^ORnameLIKEROL-STBG^ORnameLIKEROL-IronPort');
gr1.query();
while (gr1.next()) {
var arr_groups_restrict = gr1.sys_id.toString();
workflow.scratchpad.restricted_groups.splice(workflow.scratchpad.restricted_groups.indexOf(arr_groups_restrict), 1);
}
workflow.scratchpad.groupNames = workflow.scratchpad.restricted_groups;
gs.log(current.number + 'resrtict groups thiru' + workflow.scratchpad.groupNames);
gs.log(current.number + 'yashvstring' + workflow.scratchpad.groupNames);
gs.log(current.number + 'workflow.scratchpad.groupName' + workflow.scratchpad.groupNames);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 05:47 PM
Try this updated code
workflow.scratchpad.restricted_groups = '';
//restrict few groups for orchestration -STRY0417475
var arrayGroups = workflow.scratchpad.grps;
workflow.scratchpad.restricted_groups = arrayGroups.split(",").toString();
gs.log(current.number + 'workflow.scratchpad.groupName' + workflow.scratchpad.restricted_groups);
var gr1 = new GlideRecord('sys_user_group');
gr1.addEncodedQuery('nameLIKEROL-PCCG_CHS_MTL-ag-EBT_Net-V5^ORnameLIKEROL-PCCG_CHS_TOR-ag-EBT_Net-V5-RX^ORnameLIKEROL-PCCG_CHS_MTL-ag-EBT_Net_Admin-V5^ORnameLIKEROL-SSG-WF-SFTP-Users^ORnameLIKEROL-RPA-OFFICE-BOTS-ACCESS^ORnameLIKEROL-WF-PR-Development^ORnameLIKEROL-WF-PR-ADMIN^ORnameLIKEROL-WF-PR-ADMIN-EI^ORnameLIKEROL-WF-PR-Functional^ORnameLIKEROL-SSG-FORESCOUT^ORnameLIKERUN_NETWORK_NOC_CAN^ORnameLIKERUN_NETWORK_NOC_US_INTL^ORnameLIKERUN_NETWORKS_NOC_ESC^ORnameLIKEROL-ISS Admin^ORnameLIKEROL-ISS Operator^ORnameLIKEBMOUNICAGRP^ORnameLIKEBMOUNICAADM^ORnameLIKEADM-EPS-PE-BSM^ORnameLIKEROL-ISS^ORnameLIKEROL-MIDS Privacy^ORnameLIKEROL-PRODOPS-ACHDT^ORnameLIKEEI_BOWSS^ORnameLIKEROL - LEXMARK MARKVISION ACCESS^ORnameLIKEROL- EJM^ORnameLIKEROL-DevOpsToolsDT^ORnameLIKEROL-BMO-PR-27497-RDMP^ORnameLIKEROL-Basel_CAT_App^ORnameLIKEROL-Vignette BMO Canada^ORnameLIKEROL-SDE^ORnameLIKErol-forescout^ORnameLIKEROL-Centaur-RAF^ORnameLIKEROL-STBG^ORnameLIKEROL-IronPort');
gr1.query();
var arr_groups_restrict;
while (gr1.next()) {
arr_groups_restrict = gr1.sys_id.toString();
// check arr_groups_restrict ( sys_id ) exist in the restricted group arrayList
if(workflow.scratchpad.restricted_groups.indexOf(arr_groups_restrict) >-1){
//remove that sys_id from restricted group arrayList
workflow.scratchpad.restricted_groups.splice(arr_groups_restrict, 1);
}
}
workflow.scratchpad.groupNames = workflow.scratchpad.restricted_groups;
gs.log(current.number + 'resrtict groups thiru' + workflow.scratchpad.groupNames);
gs.log(current.number + 'yashvstring' + workflow.scratchpad.groupNames);
gs.log(current.number + 'workflow.scratchpad.groupName' + workflow.scratchpad.groupNames);
-Thanks
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 08:03 AM
hi Ashish ,
I have added log for index of value it showing -1 and that y it not getting into if loop.
var gr1 = new GlideRecord('sys_user_group');
gr1.addEncodedQuery('nameLIKEROL-PCCG_CHS_MTL-ag-EBT_Net-V5^ORnameLIKEROL-PCCG_CHS_TOR-ag-EBT_Net-V5-RX^ORnameLIKEROL-PCCG_CHS_MTL-ag-EBT_Net_Admin-V5^ORnameLIKEROL-SSG-WF-SFTP-Users^ORnameLIKEROL-RPA-OFFICE-BOTS-ACCESS^ORnameLIKEROL-WF-PR-Development^ORnameLIKEROL-WF-PR-ADMIN^ORnameLIKEROL-WF-PR-ADMIN-EI^ORnameLIKEROL-WF-PR-Functional^ORnameLIKEROL-SSG-FORESCOUT^ORnameLIKERUN_NETWORK_NOC_CAN^ORnameLIKERUN_NETWORK_NOC_US_INTL^ORnameLIKERUN_NETWORKS_NOC_ESC^ORnameLIKEROL-ISS Admin^ORnameLIKEROL-ISS Operator^ORnameLIKEBMOUNICAGRP^ORnameLIKEBMOUNICAADM^ORnameLIKEADM-EPS-PE-BSM^ORnameLIKEROL-ISS^ORnameLIKEROL-MIDS Privacy^ORnameLIKEROL-PRODOPS-ACHDT^ORnameLIKEEI_BOWSS^ORnameLIKEROL - LEXMARK MARKVISION ACCESS^ORnameLIKEROL- EJM^ORnameLIKEROL-DevOpsToolsDT^ORnameLIKEROL-BMO-PR-27497-RDMP^ORnameLIKEROL-Basel_CAT_App^ORnameLIKEROL-Vignette BMO Canada^ORnameLIKEROL-SDE^ORnameLIKErol-forescout^ORnameLIKEROL-Centaur-RAF^ORnameLIKEROL-STBG^ORnameLIKEROL-IronPort');
gr1.query();
var arr_groups_restrict;
while (gr1.next()) {
arr_groups_restrict = gr1.sys_id.toString();
// check arr_groups_restrict ( sys_id ) exist in the restricted group arrayList
gs.log(current.number + 'test' + workflow.scratchpad.restricted_groups.indexOf(arr_groups_restrict));
if (workflow.scratchpad.restricted_groups.indexOf(arr_groups_restrict) > -1) {
//remove that sys_id from restricted group arrayList
workflow.scratchpad.restricted_groups.splice(arr_groups_restrict, 1);
}
}
workflow.scratchpad.groupNames = workflow.scratchpad.restricted_groups;
gs.log(current.number + 'resrtict groups thiru' + workflow.scratchpad.groupNames);
gs.log(current.number + 'yashvstring' + workflow.scratchpad.groupNames);
gs.log(current.number + 'workflow.scratchpad.groupName' + workflow.scratchpad.groupNames);