Requested Item should go to assignment group manager for approval and then generate the catalog task

Abhijeet Anand
Tera Contributor

Hello All,

Can anyone help me to review the simple code that i have written to fetch the assignment group manager to approve the requested item and then it should generate the catalog task?

I am using Approval User activity and have written below code.

var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', current.variables.assignment_group);
gr.query();
if (gr.next()) {
var name = gr.manger.toString();
gs.log("please find the name of the manger" + name);
answer.push(name);
}

Tried using via attached configurable way as well but it is still not working and approval user activity seems to be skipped and it generates the catalog task.

I have checked and the manager field is populated in the sys_user_group form.

Thanks

1 ACCEPTED SOLUTION

Hi Abhijeet,

 

Since I answered your initial query successfully. I request you to mark my above response as correct. As far as your new code is concerned it should be as below

var gr = new GlideRecord('sys_user_grmember');

gr.initialize();
gr.group = current.variables.assignment_group;
gr.user = current.variables.requested_for;
gr.insert();
gs.log("User " + current.variables.requested_for + " has been added to group " + current.variables.assignment_group);

View solution in original post

8 REPLIES 8

suvro
Mega Sage
Mega Sage

spelling mistake "manager"

Hello Suvro, Thank you for your response, i have corrected it and the code is working fine for the approval part.

however, i have been trying to create the service catalog where if i select the user and the assigned group, the workflow will run the runscript actvity and add the user to the group automatically and close the task. Please find below a simple code for reference which i have written.

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',current.variables.assignment_group);
gr.query();
if(gr.next()){
gr.initialize();
gr.group = current.variables.assignment_group;
gr.user = current.variables.requested_for;
gr.insert();
gs.log("User " + current.variables.requested_for + " has been added to group " + current.variables.assignment_group);
}

However, when the workflow gets executed, i can see the error message in the log "terminating Adding_Assignment_group, state: finished" and the requested item is getting completed and the task is still open with no action happening on the user profile which has been selected as requested for.

Could you please check my code to see i am overlooking something again?

i have attached the screenshot of the workflow for reference.

Thanks,

Hey,

please use following code:

And Requested for is a field on the catalog item, then the code will work, if you are fetching requested for from ritm, use current.request.requested_for.toString(); in line 4

var gr = new GlideRecord('sys_user_grmember');
gr.initialize();
gr.setvalue("group", current.variables.assignment_group.toString());
gr.setvalue("user", current.variables.requested_for.toString());
gr.insert();
gs.info("User " + current.variables.requested_for.name + " has been added to group " + current.variables.assignment_group.name);
Best Regards
Aman Kumar

Hello Aman,

Thanks for the response, the above suggestion is not working as well.

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',current.variables.assignment_group);
gr.query();
if(gr.next()){
gr.initialize();
gr.setValue("group", current.variables.assignment_group.toString());
gr.setValue("user", current.request.requested_for.toString());
gr.insert();
gs.info("User " + current.request.requested_for + " has been added to group " + current.variables.assignment_group);
}