Create a UI action button to create a new task and copies everything from RITM or another task

tcorniels
Tera Contributor

I have need of a new UI action button located on the request item form (or task form, I don't really care which it's on) that creates a new task and copies all variable data from the RITM or another TASK and assigns it to a different group.  I've got the startings of a UI Action and put it on the request item form but really am not sure how I would proceed with getting the variable fields on there.  Any insights would appreciated.

 

find_real_file.png

 

 

5 REPLIES 5

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

You can use

billtask.work_notes=current.variables.variable_name1 +','+current.variables.variable_name2; // so-on

BALAJI40
Mega Sage

Hi,

Try the below script to create a task with request item details along with variables.

//var req = new GlideRecord('sc_req_item');
//req.get('6f8a89ff1b09bc10a80140c1b24bcb53');

var sc = new GlideRecord('sc_task');
sc.newRecord();
sc.setValue('short_description', current.getValue('short_description'));
sc.setValue('description', current.getValue('description'));
sc.setValue('assignment_group', current.getValue('assignment_group'));
sc.setValue('request_item', current.getValue('sys_id'));
sc.setValue('request', current.getValue('request'));

// add required fields

var recSysId = sc.insert(); // create catalog task

// to copy variable on catalog task
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item.numberSTARTSWITH' + req.getValue('number'));
gr.query();
while (gr.next()) {

    var gr1 = new GlideRecord('sc_item_variables_task');
    gr1.newRecord();
    gr1.setValue('task', recSysId);
    gr1.setValue('variable', gr.sc_item_option.item_option_new.toString());
    gr1.insert();
}

 

Note: from the screenshot, no need to mark the button as a client callable so remove it.

John Zhang1
Kilo Patron
Kilo Patron

current.variables.variableName is syntax to get variable value if UI action on the request item form, but if UI action button on sc_task form and you want to copy all variable values from RITM, you need to change your query.

JustinB1
Tera Contributor

I've been looking for something like this. I placed it inside a UI Action button on sc_req_item but it doesn't copy over the variables. any idea why?