How to create duplicate catalog task on RITM using workflow run script ?

Santhosh15
Tera Guru

Hello All,

I am trying to create duplicate Catalog task in RITM using workflow run script but it is not working.

Could you please help me on this issue.

I am using this below script on workflow run script for creating catalog task, but it is not working.

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gs.info("Sys ID " + current.sys_id);
while(gr.next())
    {
        var sd = "Short Description: "+ gr.short_description;
        var d = "Description: "+ gr.description;
        
        var r = new GlideRecord('sc_task');
        gs.info("Number " + gr.number);
        r.initialize();
        r.short_description = sd;
        r.description = d;
        r.state = 1;
        r.name = gr.name;
        r.requested_for = gr.requested_for;
        r.priority = gr.priority;
        r.assignment_group = gr.assignment_group;
        r.request_item = current.sys_id;
        r.request = gr.request;
        r.insert();
    }

 

@Ankur Bawiskar 

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello @D Kumar Swamy ,

you need to mark two changes to your script

1) Add gr.query();

2) You need not map requested for field as its coming from Request-->RITM->catalog task so it will be same as RTIM even if you don't map

try below script

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gr.query()
gs.info("Sys ID " + current.sys_id);
while(gr.next())
    {
        var sd = "Short Description: "+ gr.short_description;
        var d = "Description: "+ gr.description;
        
        var r = new GlideRecord('sc_task');
        gs.info("Number " + gr.number);
        r.initialize();
        r.short_description = sd;
        r.description = d;
        r.state = 1;
        r.name = gr.name;
        r.priority = gr.priority;
        r.assignment_group = gr.assignment_group;
        r.request_item = current.sys_id;
        r.request = gr.request;
        r.insert();
    }

Please mark my answer correct if it helps you

View solution in original post

3 REPLIES 3

Vaibhav Dane
Tera Expert
Tera Expert

Hi Swamy,

 

You have not queried the table. Please add gr.query() after gr.addQuery('request_item',current.sys_id); and your code will work.

 

Please mark correct if helpful.

 

Regards,

Vaibhav Dane

Mohith Devatte
Tera Sage
Tera Sage

Hello @D Kumar Swamy ,

you need to mark two changes to your script

1) Add gr.query();

2) You need not map requested for field as its coming from Request-->RITM->catalog task so it will be same as RTIM even if you don't map

try below script

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gr.query()
gs.info("Sys ID " + current.sys_id);
while(gr.next())
    {
        var sd = "Short Description: "+ gr.short_description;
        var d = "Description: "+ gr.description;
        
        var r = new GlideRecord('sc_task');
        gs.info("Number " + gr.number);
        r.initialize();
        r.short_description = sd;
        r.description = d;
        r.state = 1;
        r.name = gr.name;
        r.priority = gr.priority;
        r.assignment_group = gr.assignment_group;
        r.request_item = current.sys_id;
        r.request = gr.request;
        r.insert();
    }

Please mark my answer correct if it helps you

Santhosh15
Tera Guru

 

thanks for all those who replied me