Announcements
Hi Everyone
I have a requirement from customer to assign specific address book to all newly created customers. To achieve this, I added a post event on Insert method and am trying to assign the address book in Event handler class method.
public static void postInsertRecordHandler(XppPrePostArgs _args) { CustTable custTable; CustTableEventHandler custTableEventHandler; custTable = _args.getThis(); custTableEventHandler = new CustTableEventHandler(custTable); custTableEventHandler.assignAddressBook(); } public void assignAddressBook() { container addressBooks = ["ALL"]; DirAddressBookParty::createPartyRelationsByName(custTable.Party, addressBooks); info(strFmt('assignAddressBook() - All addressbook assigned to %1-%2-%3-%4', custTable.AccountNum, custTable.Party, custTable.dataAreaId, custTable.RecId)); }
The code is running successfully but it is not inserting record in DirAddressbookParty table.
Will appreciate if anyone of you can let me know if I am missing anything for achieving the requirement.
Thanks in advance.
Haroon
So is it now clear, do you still have open issues?
writeAddressBookParty method of DirPartyFormHandler class flushes all existing address book(s) assigned means it is also deleting the record added by event handler class.
I agree. But to find out why it is missing, you need to debug.
We have asked you to debug quite many times. Do you know how to debug? Have you debugged it? Why can't you share the findings with us? You really need to know how to debug in order to develop code.
The only missing thing is the record in DirAddressBookParty which was not added even it showed RecId (5637147599) in infolog.
Thanks! Now the only missing thing is the description about what you found out when debugging the code that doesn't work as expected.
There is no error while creating customer record so I presume it is a successful execution. Regarding, your second question I also tried executing this code and it successfully created record in a custom table.
public void createBusinessLine() { BusinessLine businessLine; businessLine.clear(); businessLine.BusinessLineId = custTable.AccountNum; businessLine.Name = custTable.name(); businessLine.insert(); }
Regarding table browser image sort by recid descending, I have updated in my original post.
Are these screenshots from the succesful or unsuccesful execution? Also what do you mean by "I tried creating record in another custom table and it went well"? Is it in any way related to the current problem that we are discussing?
The table browser is not sorted by RecId descending so we can't see if the new RecId 5637147599 is there or not.
Hi Nikolaos
I tried creating record in another custom table and it went well but in case of DirAddressBookParty (DABP) it is not going through. I also tried running this class separately in a job and that successfully created record in DABP table.
Here are the screenshot you require:
Hi,
thanks for this info. Could you also share with us all the learnings from your debugging? Thanks!
And, could you share screenshots where we see the infolog from the second piece of code (displaying RecId of the created DirAddressBookparty) and a screenshot from Table browser, where we see latest records in that table, sorted by RecId descending. Thanks!
I tried these two methods one by one but neither worked.
public void assignAddressBookV1() { container addressBooks = ["ALL"]; DirAddressBookParty::createPartyRelationsByName(custTable.Party, addressBooks); info(strFmt('assignAddressBook() - All addressbook assigned to %1-%2-%3-%4', custTable.AccountNum, custTable.Party, custTable.dataAreaId, custTable.RecId)); }
public void assignAddressBookV2() { DirAddressBook dirAddressBook; DirAddressBookParty dirAddressBookParty; DirAddressBookName addressBookName; addressBookName = 'ALL'; dirAddressBook = DirAddressBook::find(addressBookName); if (custTable.RecId && dirAddressBook.RecId) { try { ttsBegin; dirAddressBookParty.clear(); dirAddressBookParty.initValue(); dirAddressBookParty.AddressBook = dirAddressBook.RecId; dirAddressBookParty.Party = custTable.Party; dirAddressBookParty.insert(); ttsCommit; info(strFmt('assignAddressBookNew() - All addressbook assigned to %1-%2-%3-%4-%5', custTable.AccountNum, custTable.Party, custTable.dataAreaId, custTable.RecId, dirAddressBookParty.RecId)); } catch { } } }
In fact, the infolog in 2nd method is also showing RecId for DirAddressBookParty table.
André Arnaud de Cal...
294,079
Super User 2025 Season 1
Martin Dráb
232,860
Most Valuable Professional
nmaenpaa
101,158
Moderator