I want to create a new record using a workflow

lexy
Kilo Expert

Using a workflow, I want to create a new record on a table. However, this is creating multiple records. In addition,

I would also like to create a new record related record in the related table of proc_po_item.

var gr = new GlideRecord('proc_po');

gr.query();

gr.initialize();                            

gr.vendor_account = current.variables.u_first_name; //variables.u_first_name is the field from the variable this should be

gr.number = current.variables.u_last_name;

gr.insert();

17 REPLIES 17

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Lexy,



Replace gr.setValue('requested_by', current.requested_for);   with


gr.setValue('requested_by', current.request.requested_for);



Code for the Child record (proc_po_item table): Make sure to create an AFTER business rule and put few log statements to check


Thanks a lot Pradeep. Requested_for worked, but the child table creation did not work. I will continue to review and try other approaches. I appreciate your help.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

You are very welcome Lexy. From the screenshot, I see child table has a field "Purchase order" which refers to the parent table record. If that is correct, then please share the column name of the field.


It worked, thanks a lot


Using the same model,



I am trying to have the requested item and the list price of my item display on the proc_po_item table and doesn't seem to be working. My code is below. The "product_catalog" is a reference field. I can't seem to see why it is not working



var gr = new GlideRecord('proc_po_item');


                              gr.addQuery('purchase_order', current.sys_id);//reference field on related list table


                              gr.query();


                              if (!gr.next()) {


                                                              gr.newRecord();


                                                              gr.purchase_order = current.sys_id;


                                                              gr.list_price = current.cat_item.price; //Price of the catalog item


                                                              gr.vendor = current.vendor;


                                                              gr.setValue('product_catalog', current.cat_item.name); // Catalog item name


                                                              gr.insert();


                              }




find_real_file.png