- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2022 11:37 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2022 01:08 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2022 11:40 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2022 11:57 PM
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:
---------------------------------------------------------
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2022 12:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2022 12:38 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader