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

sumeet_n
Kilo Guru

is that happening via a script? how are you populating the table name automatically as of now?


Well, therein lies my problem. In the existing functionality, those records are being generated strictly based on their relationship to other tables. There are no business rules or anything generating those. So, to answer your question, no it's not happening via script. I don't know what process in the system is causing them to be generated, I just know they are being generated. I'd dare to guess that it's something to do with how the system handles referenced records when they are related a certain way?? That's a shot in the dark though.


Maybe this will give a little context as well. I have another table called CPG Data that is extended from the previously mentioned Approval Base table. See below..


find_real_file.png



So when I create a record on this table and fill in the approval level required for it here in the Map ID field...


find_real_file.png


it will create a record on the Approval Base table.


Okay, this is interesting.



1. Is the table Angular ToDo List, extended from this Approval Base table? May be that is the reason it works well. Cause that is what happens with OOB approval table as well - you dont have to take care of source table field.



2. Do you think you can try your chances by creating a field of type 'Table Name' ?


1) No, the Angular To Do List is not extended from any other table, it's a standalone. Keep in mind though, that example I pasted, I manually entered those values to make sure the OOB functionality of the document_id field would work. Doing it using the method of creating a record on a different table, does not work. I get the same result as the other instance.



2) I did some searching on this in my other instance and I noticed for the wf_context table, there is a field that has a "Type" of "Table Name". I was looking for this in my instance and it is not an option when creating a new row in the table. I've listed my options below. Since that wasn't an option, my current field is just a String field.


find_real_file.png