Individual approval activity for each selected item in List collector. So that i can add other activities based on individual approvals

nithyamaruthu
Tera Expert

Hi,

I have a List collector field(Applications) in the form. 

The approver are different for each selected application and it was derived from master table.

Approval process begins after submitting the form. Here I can set all approvals in one approval user activity by selecting the advanced and writing script in Additional approvers script field. But in my case after each approval based on the selected application I have to add other activities such as Add user to AD. For some applications the user can get approval and added in the AD. But for other applications he selected he can not get approval so no need to add to AD.

As of now i tried switch case for list collector. But for this i have to check all the applications present in the list collector table. It is not a good practice. I like to have some looping concept where for first selected item i can create a approval activity and then if approved a Add user to AD activity. then for second item, etc. till the length of the selected items. But all of the above should be parallel.

find_real_file.png

Instead of using the below case statement what else i can use?

find_real_file.png

1 ACCEPTED SOLUTION

nithyamaruthu
Tera Expert

Best practice is to split the request to multiple requested items with each list filter selection. And running workflow on each item.

 

find_real_file.png

I have used a Run script in the workflow to split the items.

 

generate();
function generate() {
//Sys IDs of Variables in the "Qlik Access Request" catalog item
var Requested_By='8ba1eee1db1d5f000194d36fdf9619e2';

var requested_behalf='d4cb4cd1db2197400194d36fdf96192f';

var Qlik_Appln='25431b01dbad57400194d36fdf96193b';

var unit='15895705dbad57400194d36fdf961920';

var tsu='319a1b85dbad57400194d36fdf9619cd';

var nau='90da9f05dbad57400194d36fdf96199e';

var fsu='2efa9b85dbad57400194d36fdf96197e';

var cci='560b9f85dbad57400194d36fdf96193b';

var ind='0f1b5f85dbad57400194d36fdf9619b6';

var cor='8b2b9b85dbad57400194d36fdf961985';

var Power_User='cf62662ddb1d5f000194d36fdf96197a';

var business_reason='9b479a9b133a57403b49fc04e144b0ae';

var subbusiness_unit='e8e89a9b133a57403b49fc04e144b0c3';


var listStr = current.variables.Qlik_Appln.toString(); //Variabile List Collector da Splittare


var list = listStr.split(',');


var IDritm;


for (var i = 0; i < list.length; i++) {


var ritm = new GlideRecord('sc_req_item');

ritm.initialize();
ritm.newRecord();


ritm.request = current.request;
ritm.cat_item ='d2e0eae9db1d5f000194d36fdf9619d3'; // updating Qlik Access Request

ritm.u_multiritm=true;

// ritm.variables.Qlik_Appln=current.variables.Qlik_Appln;
// ritm.variables.Requested_for=current.variables.Requested_for;
// ritm.variables.Power_User = current.variables.Power_User;
//ritm.allthefielduneed;



ritm.opened_by = current.opened_by;



var sysID = ritm.insert();

//Add variables to the Request Item


addVariable(sysID, Qlik_Appln,list[i],300);


addVariable(sysID, Requested_By,current.variables.Requested_By,100);


addVariable(sysID, requested_behalf,current.variables.requested_behalf,200);


addVariable(sysID, unit,'Please select the unit(s) for which you need access',400);


addVariable(sysID, tsu,current.variables.tsu,500);


addVariable(sysID, nau,current.variables.nau,600);


addVariable(sysID, fsu,current.variables.fsu,700);


addVariable(sysID, cci,current.variables.cci,800);
addVariable(sysID, ind,current.variables.ind,900);
addVariable(sysID, cor,current.variables.cor,1000);
addVariable(sysID,subbusiness_unit,current.variables.subbusiness_unit,1010);
addVariable(sysID, Power_User,current.variables.Power_User,1100);
addVariable(sysID,business_reason,current.variables.business_reason,1200);

//Start the workflow on all the created Items

startWf(current.request);

}
}


function addVariable(ritm,varID,value,order) {


var variable = new GlideRecord('sc_item_option');


variable.initialize();


variable.item_option_new = varID;


variable.value = value;


variable.order = order;


var sysID = variable.insert();



var itemm2m = new GlideRecord('sc_item_option_mtom');


itemm2m.initialize();


itemm2m.request_item = ritm;


itemm2m.sc_item_option = sysID;


itemm2m.insert();


}


function startWf(request) {


var ritm = new GlideRecord('sc_req_item');


ritm.addQuery('request',request);


ritm.addQuery('sys_id','!=',current.sys_id);


ritm.addNullQuery('context');


ritm.query();



while (ritm.next()) {


ritm.setForceUpdate(true);


ritm.update();


}


}

 

View solution in original post

7 REPLIES 7

Dubz
Mega Sage

Hi Nithy,

 

Can't you just use a for loop to run through the list collector contents and perform actions in each one depending on their details?

 

var list = current.u_applications_field.getValue();
var listArray = list.split(',');

var gr = new GlideRecord('u_applications_table');
for(var i=0; i<listArray.length; i++){
if(gr.get(listArray[i])){
//do your logic/calculations and whatnot here
}

 

Cheers

Dave

Hi Dave,

     Thanks! Yes. I agree. I have the following run script to loop. But here i can only get approvers or other information.

How can i create a approval activity and other orchestration activities using code?

var qlikApps = [current.variables.Qlik_Appln];
var qlikAppsList = qlikApps.toString().split(",");
var qlikAppsCount = qlikAppsList.length;
gs.addInfoMessage(qlikAppsCount);
for(var x = 0; x < qlikAppsCount; x++) {
var qlikAppname= qlikAppsList[x];
var gr=new GlideRecord('u_qlik_access_security');
gr.addQuery('u_application',qlikAppname);
gr.query();
while(gr.next())
{
if(gr.u_direct_approval=='true'){
workflow.scratchpad.Approver=gr.u_approver;
}
if(gr.u_direct_approval=='false')
{
workflow.scratchpad.tsuApprover=gr.u_tsu_approver;
workflow.scratchpad.nauApprover=gr.u_nau_approver;
workflow.scratchpad.fsuApprover=gr.u_fsu_approver;
workflow.scratchpad.cciApprover=gr.u_cci_approver;
workflow.scratchpad.indApprover=gr.u_ind_approver;
workflow.scratchpad.corApprover=gr.u_cor_approver;
workflow.scratchpad.Approver=gr.u_approver;
}}}

Hi Nithy,

 

Where have you put that code? Looks like an onDisplay business rule? If you add a new user - approval activity to your workflow (or modify an existing one) in the approvers section you can tick the advanced checkbox and this gives you the option to run scripts to define approvers. you can still reference the current object so you can take your code above and put it in there and instead of populating the scratchpad you can add the approvers to the answer array. You want to be passing back sys_id's so if your approver fields are reference fields you'll have to do some more work to get the sys_id of the user record.

 

var answer = [];
var qlikApps = [current.variables.Qlik_Appln];
var qlikAppsList = qlikApps.toString().split(",");
var qlikAppsCount = qlikAppsList.length;
gs.log(qlikAppsCount);

for(var x = 0; x < qlikAppsCount; x++) {
 var qlikAppname= qlikAppsList[x];
var gr=new GlideRecord('u_qlik_access_security');
gr.addQuery('u_application',qlikAppname);
gr.query();
while(gr.next())
 {
 if(gr.u_direct_approval=='true'){
 answer.push(gr.u_approver.getValue);
 }
 if(gr.u_direct_approval=='false')
 {
answer.push(all your other approvers!)
}

I used a run script to capture the approvers.

If i use the below,

answer.push(all your other approvers!)

I can not track each approval individually. If you see my attached workflow after each approval user approved the request I am processing more. i.e. I am adding the user to Application specific Active Directory group. If i combine all approvers in one approval activity then I can not perform other activities.