Insert to other Table on Submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 03:47 AM
Use Case:
I have a custom table(u_vendor). In the Form it has Type and Name which is mandatory.
Type is a Choice Field: Vendor or Merchant
I want to save all records having type "Vendor" in the u_vendor table and all records having type "Merchant" in the custom table(u_merchant) onSubmit.
I did achieve saving all the type merchant in the merchant table but it will also be saved in the vendor table.
How to achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 05:44 AM
How are you doing this? You are on one table, filling in the data and expect it to go to another table if a certain choice is made? This is a weird setup. I would just create a record producer for it, so it will be easy to maintain. Your UI action will need to create a new record with data that's not yet in the database and create a record on a different table with that data and needs to abort inserting it in the current one. I'm not sure why you have 2 tables at all, but there must be a reason. Best practice is to create records on the table you are on. Only easy way around it, is a record producer where you decide which record it must be, based on the given selection.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 05:49 AM
I think depending on the value of the Type field, insert the record into the appropriate table (u_vendor or u_merchant).
You can use below sample template:
(function executeRule(current, previous /*null when async*/) {
// Check if Type field is "Vendor" or "Merchant"
var type = current.getValue('type');
if (type == 'Vendor') {
// Save record in u_vendor table
var vendorRecord = new GlideRecord('u_vendor');
vendorRecord.initialize();
vendorRecord.setValue('name', current.name);
// Set other fields if needed
vendorRecord.insert();
} else if (type == 'Merchant') {
// Save record in u_merchant table
var merchantRecord = new GlideRecord('u_merchant');
merchantRecord.initialize();
merchantRecord.setValue('name', current.name);
// Set other fields if needed
merchantRecord.insert();
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 05:55 AM
You can have 2 BR's,
place a condition on the type and you can write the below code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 11:32 PM
thanks for all the replies. but i got it already
I made a UI Action and put my script in there depending on type insert into Fruits or Vegetables.
Thanks a lot!