Can I change the Parent of a Task?

Daniel50
Kilo Guru

Morning guys. 

Just a quick one for today: can I change the parent of a Work Order Task to attach the WOT to another WO? I guess not, but some of you smart people might have an idea. 🙂

find_real_file.png

 

Daniel

1 ACCEPTED SOLUTION

Thameem Ansari
Giga Guru
Giga Guru

Hi Daniel, 

OOB we can't do it. but if you are willing to use a background script please use the below script to achieve it

var taskNumbers = "WOT0008001";// number of the work order task record. if you want to update it give comma separet values like "WOT0008001,WOT0008002"

var newParentNumber="WO0008003"// number of the work order we are gonna use as a new parent


var woGr=new GlideRecord('wm_order');
woGr.addQuery('number',newParentNumber);
woGr.query()
if(woGr.next()){

var wot=new GlideRecord('wm_task');
wot.addQuery('number','IN',taskNumbers);
wot.query();

while(wot.next()){
wot.setWorkflow(false)
gs.info("update the parent of workorder task :  "+wot.number+"  -- new parent :  "+ newParentNumber+"  ---- old parent : "+wot.parent.number );
    wot.parent= woGr.sys_id;
    wot.update()

}

}

 


Please mark it as helpful/correct If my answer is helpful in any way,

Best regards,

Thameem

View solution in original post

2 REPLIES 2

Thameem Ansari
Giga Guru
Giga Guru

Hi Daniel, 

OOB we can't do it. but if you are willing to use a background script please use the below script to achieve it

var taskNumbers = "WOT0008001";// number of the work order task record. if you want to update it give comma separet values like "WOT0008001,WOT0008002"

var newParentNumber="WO0008003"// number of the work order we are gonna use as a new parent


var woGr=new GlideRecord('wm_order');
woGr.addQuery('number',newParentNumber);
woGr.query()
if(woGr.next()){

var wot=new GlideRecord('wm_task');
wot.addQuery('number','IN',taskNumbers);
wot.query();

while(wot.next()){
wot.setWorkflow(false)
gs.info("update the parent of workorder task :  "+wot.number+"  -- new parent :  "+ newParentNumber+"  ---- old parent : "+wot.parent.number );
    wot.parent= woGr.sys_id;
    wot.update()

}

}

 


Please mark it as helpful/correct If my answer is helpful in any way,

Best regards,

Thameem

Daniel50
Kilo Guru

Hi Thameem

Wow, that is really awesome! Thank you very much for this cool solution! That helped me a lot!

Daniel