How to create 4 tasks in incident by UI action Button on a form level?

krishna svg
Tera Contributor

How to create 4 tasks in incident by UI action Button on a form level through scripting?

3 REPLIES 3

Vishwa Pandya19
Mega Sage

Hello,

 

You can use below code in UI Action.

 

var grtask= new GlideRecord('incident_task');

for(var i = 0; i<4;i++){
grtask.initialize();

grtask.short_description=current.short_description;

grtask.assignment_group=current.assignment_group;

grtask.insert();

}

 
current.worknotes='Incident task is created-'+grtask.number;

 

 

If my answer has helped you in any way please mark it as correct or helpful.

Seraj
Tera Guru

Hi @krishna svg ,

Create One UI Button "Create Task"

Define the condition on which you want to be appear or visible UI button

Use this script for incident task

var grtask= new GlideRecord('incident_task');

for(var i = 0; i<4;i++){
grtask.initialize();
grtask.incident=current.sys_id;//Link the incident with task record
grtask.short_description=current.short_description;
grtask.assignment_group=current.assignment_group;

grtask.insert();
grtask.update();

}
current.worknotes='Incident task is created-'+grtask.number;
current.update();
action.sendRedirectURL(cureent);

 

If you want to create task only then

use this script

var grtask= new GlideRecord('task');

for(var i = 0; i<4;i++){
grtask.initialize();
grtask.parent=current.sys_id;//Link the incident with task record
grtask.short_description=current.short_description;
grtask.assignment_group=current.assignment_group;

grtask.insert();
grtask.update();

}
current.worknotes='Incident task is created-'+grtask.number;
current.update();
action.sendRedirectURL(cureent);


Regards,

Seraj

Community Alums
Not applicable

Hi @krishna svg ,

I tried your problem in my PDI and it works for me please refer below images and script 

I create UI action which is not client callable and added below script 

var taskGR = new GlideRecord('task');

for(var i = 0; i<4;i++){
taskGR.initialize();
taskGR.parent = current.sys_id;//Link the incident with task record
taskGR.short_description = current.short_description;
taskGR.description = current.description;
taskGR.assignment_group = current.assignment_group;

taskGR.insert();
}

SarthakKashyap_0-1714635977177.png

 

Result : 

SarthakKashyap_1-1714636055045.png

When I click UI Action - Create Task it created 4 tasks

SarthakKashyap_2-1714636118976.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak