Create Task by UI Action

David278
Kilo Contributor

I am trying to create a task via a UI Action on the Change Request form.

The idea is that Change Manager can click on a UI action to quickly assign a task to resolver group with some pre-filled values like short description, description, priority, assignment group & assigned to.

The UI Action that doesn't show up on the change form to create a task.

 I know I must be missing something obvious in the UI action code, but I can't figure out what it is.

 

this is my code :

function createtask(){

gsftSubmit(null, g_form.getFormElement(), 'create_task');
}
if (typeof window == 'undefined')
serverUpdate();

function serverUpdate(){
var task = new GlideRecord('change_task');
task.initialize();
task.change_request = current.sys_id;
task.short_description = "SD";
task.description = "yes";
task.priority = "1";
task.assignment_group.sys_id = "c7115ecyec0i8056700a122a0f7901d02";
task.assigned_to = "";
task.insert();
action.setRedirectURL(current);

}

 
1 ACCEPTED SOLUTION

Pranay Tiwari
Kilo Guru

Actually your condition is not meet that's why it will not showing in your form.

remove the condition from UI Action and check it.

 

Mark correct or helpful if it helps you.

View solution in original post

9 REPLIES 9

1st i forgot to checkout the form button after post i were checkout,yes were check it,but when i click on that it will not create task.

David278
Kilo Contributor

find_real_file.png

Did you check the button

 

try removing conditions and check whether its appearing or not

 

Regards

Pranav

Mark my Responses as Correct and Helpful if you find it relevant.

Pranay Tiwari
Kilo Guru

Actually your condition is not meet that's why it will not showing in your form.

remove the condition from UI Action and check it.

 

Mark correct or helpful if it helps you.

ChanakyaMekala
Kilo Guru

gsftSubmit() function has to be used if you want to perform client side operation and server side operation with the button, as you just want to create a change task then you can directly use Server side script.

 

I have wrote this in PDI and it worked, please try it:

Name: Create Change Task

Active : Checked(true)

Show Update: Checked(true)

Condition: gs.hasRole('itil')&&(current.state!='3')&&(current.state!='4')  // only ITIL users will be allowed to access the button if the state of change request is not closed or cancelled.

 

Script:

var gr = new GlideRecord('change_task');
gr.initialize();
gr.short_description=current.short_description;
gr.description=current.description;
gr.change_request=current.sys_id;
gr.assignment_group='a715cd759f2002002920bde8132e7018'; or gr.assignment_group=current.assignment_group;
gr.insert();
action.setRedirectURL(current);
gs.addInfoMessage("Change Task has been created:"+gr.number);


If you want do both operations try like this:

Name: Create Change Task

Active : Checked(true)

Show Update: Checked(true)

Client - Checked(True)

Condition: gs.hasRole('itil')&&(current.state!='3')&&(current.state!='4')  // only ITIL users will be allowed to access the button if the state of change request is not closed or cancelled.

 

Script:

function runClient(){
confirm("Do you want to create Change task");

gsftSubmit(null, g_form.getFormElement(), 'create_chg_task'); //MUST call the 'Action name' set in this UI Action

}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runServer();

//Server-side function
function runServer(){

var gr = new GlideRecord('change_task');
gr.initialize();
gr.short_description=current.short_description;
gr.description=current.description;
gr.change_request=current.sys_id;
gr.assignment_group='a715cd759f2002002920bde8132e7018';
gr.insert();
action.setRedirectURL(current);
gs.addInfoMessage("Change Task has been created:"+gr.number);

}