Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Get sys_id task from request item

rapbriqu
Kilo Expert

Hi community,

I need to get the sys_ID task from a new request item. Can you help me please

(The task is create by a workflow)

find_real_file.png

Thanks

1 ACCEPTED SOLUTION

You are getting the request sys_id not requested item. Here is your updated script. Try this



gs.include('Cart');


var cart= new global.Cart();


var item=cart.addItem('put in the sys_id of catalog item');


var rc= cart.placeOrder();


var reqID=rc.getValue('sys_id');


var body={};


var scTaskID='';


var scTask= new GlideRecord('sc_task');


scTask.addQuery('request',reqID);


scTask.query();


while(scTask.next()){


if(scTaskID.length >0){


scTaskID+=scTask.getValue('sys_id')+',';


}


else{


scTaskID=scTask.getValue('sys_id');


}


}


body.name=scTaskID;


}




Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

7 REPLIES 7

Chuck Tomasi
Tera Patron

Hi Raphael,



Are you doing this in a business rule? If so, what table are you working with?



Suffice it to say, if you've got the sys_id of the requested item (sc_req_item) record, I'll assume via a business rule on that table, then you can find any/all tasks that have that request item as a parent.



var scTask = new GlideRecord('sc_task');


scTask.addQuery('parent', current.getValue('sys_id'));


scTask.query();



while (scTask.next()) {


        // Do what you need with the returned records


}


hi ctomasi,



Nice to meet you (i seen some video with you )



I'm doing this in a Script rest resource. And i'm sure your solution is good but it's not working for the moment i try this but it return error



find_real_file.png



{
  "error": {
  "message": "The undefined value has no properties.",
  "detail": "ConversionError: The undefined value has no properties. (<refname>; line 56)"
  },
  "status": "failure"
}


You are getting the request sys_id not requested item. Here is your updated script. Try this



gs.include('Cart');


var cart= new global.Cart();


var item=cart.addItem('put in the sys_id of catalog item');


var rc= cart.placeOrder();


var reqID=rc.getValue('sys_id');


var body={};


var scTaskID='';


var scTask= new GlideRecord('sc_task');


scTask.addQuery('request',reqID);


scTask.query();


while(scTask.next()){


if(scTaskID.length >0){


scTaskID+=scTask.getValue('sys_id')+',';


}


else{


scTaskID=scTask.getValue('sys_id');


}


}


body.name=scTaskID;


}




Thanks,


Abhinay



PS: Hit like, Helpful or Correct depending on the impact of the response


What else ? your answer is perfect !



Thanks you Abhinay and thanks everybody !