How to push groups in a Approval - Group in the workflow

andrew_ajon
Mega Contributor

Hi Everyone,

I am not a developer material but I am trying to make this work but just can't seem to be able to do it even after looking into some articles here in community.

I will try my best to discuss the problem that is need to be solved. Hopefully, some of you can help.

Problem: Need to insert groups in the "Approval - Group"   in the workflow tasked to approve the change based on their unit

Field in Change form: Unit

Sample data:

Unit 1 (Group 1, Group 2)

Unit 2 (Group 2, Group 3)

Unit 3 (Group 4, Group 5)

My understanding on how this will be done, but please correct me if I am wrong:

answer = [];

var thisUnit = current.u_unit

if ('thisUnit' == 'Unit 1') {

answer.push('sysid_Group1', 'sysid_Group2');

} return;

Can anyone please direct me on how I can implement this depending on the unit selected in the field u_unit? I would really appreciate it a lot. Thank you.

1 ACCEPTED SOLUTION

if ('thisUnit' == 'Unit 1')


{


answer.push('sysid_Group1'');


answer.push('sysid_Group2'');


}



else if ('thisUnit' == 'Unit 2')


{


answer.push('sysid_Group2'');


answer.push('sysid_Group3'');


}



else if ('thisUnit' == 'Unit 3')


{


answer.push('sysid_Group4'');


answer.push('sysid_Group5'');


}



Add else to your script and it will solve the problem.


View solution in original post

8 REPLIES 8

Deepak Ingale1
Mega Sage

Can you check with below code?



Case 1



answer = [];


var thisUnit = current.u_unit


gs.log('thisUnit: ' + thisUnit // Do this and check what LOG statement provided. Ideally it should provide the sys_id of the u_unit record if that is the reference field.


if ('thisUnit' == 'Unit 1') // if log statement provided sys_id, replace 'Unit 1' with sys_id of thisUnit which you have stored.


{


answer.push('sysid_Group1'');


answer.push('sysid_Group2'');


}




Case 2



answer = [];


var thisUnit = current.u_unit.getDisplayValue();


gs.log('thisUnit: ' + thisUnit // This will give you the display value of field.


if ('thisUnit' == 'Unit 1') // here you wont require sys_id to passon if your gs.log provided displayvlaue


{


answer.push('sysid_Group1'');


answer.push('sysid_Group2'');


}


Hi Deepak,



Thanks for your reply on this. The script is working great! However, it is only for one one unit. How would the script be if it will be for more than one unit? Say I still have Unit 2, Unit 3 and Unit 4?



Regards,


Andrew


Hi Andrew?



You are saying that there may be more than 1 unit at a time?


How you are getting those units? How you are defining them? Do you have some list collector for this?


Hi Deepak,



The requirement is whenever I select a Unit, push this Group/s as approver/s. I would probably need multiple If statements to cover the other 3 units. I tried doing multiple if statements as below but it is just being skipped in the workflow.



if ('thisUnit' == 'Unit 1')


{


answer.push('sysid_Group1'');


answer.push('sysid_Group2'');


}



if ('thisUnit' == 'Unit 2')


{


answer.push('sysid_Group2'');


answer.push('sysid_Group3'');


}



if ('thisUnit' == 'Unit 3')


{


answer.push('sysid_Group4'');


answer.push('sysid_Group5'');


}



Regards,


Andrew