Assign the catalog task automatically when it gets closed

Vamsi26
Tera Contributor

Hello,

I am having requirement As an IT fulfiller I want to close an opened task in one click and to have my name automatically applied on "Assigned to" field if it is empty.

Here the Assigned to should be filled in automatically when closing the sc_task record if I am member of the Assignment Group. Can you please help me how can i achieve this.

 

Thanks.

1 ACCEPTED SOLUTION

Hi,

then do this

I assume the logged in user is member of that group

function closeTask(){
    g_form.setValue('state', 3);
    //Call the UI Action and skip the 'onclick' function
    gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    updateTask();

function updateTask(){

    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("group", current.assignment_group);
    gr.addQuery("user", gs.getUserID()); // add this line as extra query
    gr.setLimit(1);
    gr.query();
    if (gr.next()) {
        current.assigned_to = gr.user;
    }

    current.state = 3;
    current.update();
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Is the catalog task not already assigned to someone before closure?

It should be having assigned to as that user needs to work on that catalog task

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hello Ankur,

As I am an IT fulfiller the task is assigned to my group(i,e Field Services Group). If I click on Close Task as i am member of group the "Assigned to" field should be filled with my name.

Please refer below images:

find_real_file.png

 

---------------------------------------------------------

find_real_file.png

 

 

Thanks.

You can try this.

1. Create an onSubmit Client Script and write below code.

var action = g_form.getActionName();
if(action == "close_sc_task" && g_form.getValue("assigned_to") == ""){
g_form.setValue("assigned_to",g_user.userID);
}

I am assuming that the button is clicked by the user who is member of Assignment group.

 

 

I hope the answer helps, You can thank me by Marking the answer Correct or Helpful.

Thanks,

Deepak Negi

LinkedIn

Hi,

but since the task is assigned to Field Services group somebody from that group has to start working on it and then close that

but if that is not the approach then when you click Close Task button you can update the code there

Also note you need to fill mandatory fields during task closure

Sharing the updated UI action code for Close Task

function closeTask(){
    g_form.setValue('state', 3);
    //Call the UI Action and skip the 'onclick' function
    gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    updateTask();

function updateTask(){

    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("group", current.assignment_group);
    gr.setLimit(1);
    gr.query();
    if (gr.next()) {
        current.assigned_to = gr.user;
    }

    current.state = 3;
    current.update();
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader