- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 10:50 AM
Hi
I have been trying (unsuccessfully) to automate creating a PO Line item with a run script on a workflow for a catalog form. It will give me the RITM # on the line item, but I am unable to find the right script to locate the PO number/parent (which is a string field named number) and map it to the purchase_order field on the Line Item. I have been successful creating the PO first and that script works fine and the REQ maps correctly there, but I need the PO number to map on the line item.
Any ideas on what the correct script should be?
Thanks - Nona Johnson
var po = new GlideRecord('proc_po');
po.initialize();
po.addQuery('number', current.number);
po.query();
var pol = new GlideRecord('proc_po_item');
pol.initialize();
pol.addQuery('purchase_order', current.number);
pol.addQuery('request_line', current.sys_id);
pol.query();
pol.request_line = current.sys_id;
pol.purchase_order = current.number;
pol.update();
Am wondering if my issue is because I am trying to map a string field to a reference field. Anyone have ideas on this?
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 01:21 PM
Finally figured this out - I had to find a way to get to the sys_id of the PO that I'd just created. Below is my final script. The line that really helped is "var po_sys_id = po.insert();" This gave me the sys_id of the PO I'd just created - then it was just a matter of mapping the field to this var
//create a PO and PO Line Item
var po = new GlideRecord('proc_po');
po.initialize();
var req = new GlideRecord('sc_req_item');
req.addQuery('request',current.request);
req.query();
po.init_request = current.request;
po.vendor = '66908b2b4f6b6e008a5bdec85210c73f';
po.ship_to = 'c566ea274f676e008a5bdec85210c73d';
po.status = 'requested';
po.assigned_to = '4dd67a9a485f5080b79b74407048f3b4';
po.description = 'Cost: '+ current.variables.task_purch_cost + ' Descr: ' + current.variables.task_purch_descr;
var po_sys_id = po.insert();
//create a PO Line Item
var pol = new GlideRecord('proc_po_item');
pol.initialize();
pol.addQuery('request_line', current.sys_id);
pol.query();
pol.request_line = current.sys_id;
pol.purchase_order = po_sys_id;
pol.vendor = '66908b2b4f6b6e008a5bdec85210c73f';
pol.model = '2091567cdb929b00ec45b2bd2b9619b2';
pol.insert();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 12:54 PM
If you are running this on cat item so it will create RITM
below code is basically querying proc_po table and adding Query number is RITMxxxx most likely that will not return any results.
var po = new GlideRecord('proc_po');
po.initialize();
po.addQuery('number', current.number);
po.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 01:21 PM
Finally figured this out - I had to find a way to get to the sys_id of the PO that I'd just created. Below is my final script. The line that really helped is "var po_sys_id = po.insert();" This gave me the sys_id of the PO I'd just created - then it was just a matter of mapping the field to this var
//create a PO and PO Line Item
var po = new GlideRecord('proc_po');
po.initialize();
var req = new GlideRecord('sc_req_item');
req.addQuery('request',current.request);
req.query();
po.init_request = current.request;
po.vendor = '66908b2b4f6b6e008a5bdec85210c73f';
po.ship_to = 'c566ea274f676e008a5bdec85210c73d';
po.status = 'requested';
po.assigned_to = '4dd67a9a485f5080b79b74407048f3b4';
po.description = 'Cost: '+ current.variables.task_purch_cost + ' Descr: ' + current.variables.task_purch_descr;
var po_sys_id = po.insert();
//create a PO Line Item
var pol = new GlideRecord('proc_po_item');
pol.initialize();
pol.addQuery('request_line', current.sys_id);
pol.query();
pol.request_line = current.sys_id;
pol.purchase_order = po_sys_id;
pol.vendor = '66908b2b4f6b6e008a5bdec85210c73f';
pol.model = '2091567cdb929b00ec45b2bd2b9619b2';
pol.insert();