- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2022 11:36 PM
Hi, new to coding and ServiceNow.
I've had to come up with a scenario. I've got a table called Hardware Expense Requests. Fields include Product Name, Brand, Hardware Approved, Hardware Type, Location, Quantity and Source. I want the records in this table to copy to another table called Hardware Expensed Asset List if the hardware approved field for that record is true. I'm trying to create a business rule and my javascript is very basic. So having a bit of trouble knowing what script to use from doing research online. I don't really understand what to fill in and what operators I am supposed to use. This is what I have so far. Not sure what I am missing. Help is much appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 12:01 AM
Hello,
Please following the following steps:
1. Go to Business rules list
2. Create New
3. Give any name
4. In table field select "Hardware Expense Requests" and check the "advanced" check box as true
5. In "When" field select "Asynch" or "After" (any one of these is fine)
6. Check the check box "Insert" as true
7. Condition : Hardware Approved is True
8. Go to Advanced section
9. Write the following script in it
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("u_hardware_expensed_asset_list");
gr.initialize();
gr.<field_name1> = current.<field_name1>;
gr.<field_name2> = current.<field_name2>;
gr.<field_name3> = current.<field_name3>;
//repeat above for all the required fields
gr.update();
})(current, previous);
10. Save
Now test by inserting a record in the first table, it will insert the same record in another table.
Please mark the answer correct if it helps. 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 01:00 AM - edited 10-24-2022 01:04 AM
The names of the fields which you have used with current object and gr are incorrect.
Please use the backend column names of these fields.
In the table columns, please bring "column name " field as well from where you will be able to get the correct name of the field as shown below example. You have to take the name of the field from "Column name" column.
You always have to use the correct backend names, otherwise the system will not understand which field to copy and the record will be empty
Please mark the answer correct if it helps. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2022 11:55 PM
Hi Kenny,
It would be better if you used Flow Designer.
Regards,
Edgar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 12:01 AM
Hello,
Please following the following steps:
1. Go to Business rules list
2. Create New
3. Give any name
4. In table field select "Hardware Expense Requests" and check the "advanced" check box as true
5. In "When" field select "Asynch" or "After" (any one of these is fine)
6. Check the check box "Insert" as true
7. Condition : Hardware Approved is True
8. Go to Advanced section
9. Write the following script in it
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("u_hardware_expensed_asset_list");
gr.initialize();
gr.<field_name1> = current.<field_name1>;
gr.<field_name2> = current.<field_name2>;
gr.<field_name3> = current.<field_name3>;
//repeat above for all the required fields
gr.update();
})(current, previous);
10. Save
Now test by inserting a record in the first table, it will insert the same record in another table.
Please mark the answer correct if it helps. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 12:38 AM
I think I may have done it incorrectly. The record keeps coming up as empty in the second table. These are the fields in the asset list table which I've made sure was exactly the same as the fields in the request table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 01:00 AM - edited 10-24-2022 01:04 AM
The names of the fields which you have used with current object and gr are incorrect.
Please use the backend column names of these fields.
In the table columns, please bring "column name " field as well from where you will be able to get the correct name of the field as shown below example. You have to take the name of the field from "Column name" column.
You always have to use the correct backend names, otherwise the system will not understand which field to copy and the record will be empty
Please mark the answer correct if it helps. 🙂