Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Ankit P
Mega Guru

Recently I got a requirement from one of my clients to create a single record producer to create a record on multiple tables dynamically based on a Select box variable value. Here is how we did it.

1. Create the record producer on a parent table e.g. task table.

2. Add the below script on top of your record producer script where table_name can be defined conditionally. This prevents you from doing a GlideRecord on every table you need to create a record in. And it also takes care of the attachments attached on the Record Producer.

current.sys_class_name = table_name;
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.sys_id);
attachment.query();
while(attachment.next()){
	attachment.table_name = table_name;
	attachment.update();
}

 

Note- If the producer is in a scoped application, you need to go to sys_attachment table configuration and allow update and configurations from other scopes.

Please mark helpful if it helps and don't forget to bookmark :).

Comments
MattCD
Tera Contributor

When you create a record producer the default script text recommends against this. 

Don't use `current.setValue('sys_class_name', 'xxx')` as this will trigger reparent flow and can cause data

For example, it will not create the required sc_item_produced_record entry and the variable mappings will be missing in the question_answer table.

Version history
Last update:
‎04-30-2020 02:47 PM
Updated by: