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

Where is this business rule defined? Product catalog refers to a requested item?




Thanks a lot Pradeep,


I am using scripted workflow, rather than a BR. I figure scripted workflow would be easy for other people to maintain.



I used the script below to output the Item being requested by the user


...



var gr = new GlideRecord('proc_po');


...


....


gr.short_description   = current.cat_item.name; (the value was displaed on the Short Description field)


....


....


However, when I used the code below as a quick test,



var gr = new GlideRecord('proc_po_item');



.....


.....


gr.setValue('product_catalog', current.short_description);


....


...



The value did not did not show in the reference box



find_real_file.png


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Lexy,



You can only populate the reference field with the display value. What field product catalog refers to?


Thanks a lot.



Now, I want to create an Asset, but I got this error




find_real_file.png


Chuck Tomasi
Tera Patron

Hi Lexy,



If you are simply creating a record. you don't need gr.query(), that's used to read records.



Try this alone:



var gr = new GlideRecord('proc_po');


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();