Populate Document ID Field oninsert

Ken83
Mega Guru

Hello All,

        I know this particular topic has been discussed quite a bit around the community and every document I've read has been more or less dancing around what my particular issue is. So here we go. I have created a document_id field on a custom table("Approval Base") . This approval base table is the parent table for a couple of other tables. So, my current functionality is that, on any of the extended tables(Table B or Table C), when I create a record, it will generate a new record on the approval base table where the document_id field is.

What I want to happen, is for that document_id field to get populated with the record and table name of the record that generated it. That's all. But, I can't seem to make that happen. Any suggestions on how to accomplish this?

P.S. Another article I read, mentioned querying other tables, etc. The problem with that, is that it can be a large number of tables that can generate an approval base record. I will never know exactly which table is going to generate the record so writing a query for that wouldn't quite work.

1 ACCEPTED SOLUTION

Ken83
Mega Guru

After tinkering around with the Business Rule concept suggested by sumeet.n I have a solution to populate this document_id field with the correct values. This is being done via getRecordClassName() in an after insert Business Rule. The value returned from that is the table name of the record that generated the new record and the sys_id of the new record directly relates back to a record on the originating table. This might be a unique case based on how my tables are extended from each other but nonetheless, with those 2 pieces of information, I can properly fill in the document_id field as needed. Thanks for the assist sumeet.n


View solution in original post

14 REPLIES 14

Can you manage to get the table information (sys_class_name) to be used in an insert (preferably before) BR on Approval Base table, from the relationship that you are talking about? If there is a relationship, then information about the related table should be accessible somehow. If yes, then how about writing a BR to update table field?


Well, that's where I ultimately landed and what I started trying before I decided to post this because I wasn't getting anywhere. I can continue to poke around with the BR to see if I can pull the information about the related table. I'm a little uncertain on the syntax of it though. Currently, this is what I get when I log all values during an onBefore Insert BR on the Approval Base table..


find_real_file.png


Yes I think since we dont know the exact source of creation of these records, BR is the only option we have. Can you share the code?


Here is the BR content, it's on before insert..


find_real_file.png


Ken83
Mega Guru

After tinkering around with the Business Rule concept suggested by sumeet.n I have a solution to populate this document_id field with the correct values. This is being done via getRecordClassName() in an after insert Business Rule. The value returned from that is the table name of the record that generated the new record and the sys_id of the new record directly relates back to a record on the originating table. This might be a unique case based on how my tables are extended from each other but nonetheless, with those 2 pieces of information, I can properly fill in the document_id field as needed. Thanks for the assist sumeet.n