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

Hi,

The Assigned(current.assigned_to) to is filling up with some random user from the Assignment Group, But it should be the closed person from that group.

what should be replaced for gr.user??

Thanks.

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