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

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.


Hi Deepak,



Thanks a lot! I have the else in my script already thanks for confirming, my bad. I have to fix the group and the users within it to be put to "Active" before it finally worked.



Thanks and regards,


Andrew


Tanaji Patil
Tera Guru

Hi Andrew,



I can guess form you description that your unit field is a string field and not a watch list or reference. In case if it a reference field then please replace "var thisUnit = current.u_unit;" line with "var thisUnit = current.u_unit.getDisplayValue();" in the below code.



// Set the variable 'answer' to a comma-separated list of group ids or an array of group ids to add as approvers.


If you will read the above line carefully it also says you can set the answer to a comma-separated list of group ids.



So you can simply use-


var thisUnit = current.u_unit;


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


answer = 'sysid_Group1'+','+ 'sysid_Group2';


}



Also the Case 1 mentioned by Deepak will work. Just add semi-colon at the end of first line in his code. He has mentioned with use of array.


Thanks Tanaji for pointing it out.