Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

CustTable insert() CoC get RecId

(4) ShareShare
ReportReport
Posted on by 96
Hi Community,
 
I'm working on implementing a Power App to replace a HTML/JavaScript control, see https://community.dynamics.com/forums/thread/details/?threadid=22a8446e-91bc-ef11-8ee9-6045bdd80cdd.
 
In doing so, we've decided to store a unique ID of a customer in a new custom field in CustTable so this can be passed on to the Power App. The ID is a concatenation of the RecId and some other information about the customer that the Power App needs. So every time a customer is inserted or updated, we should write to this custom field.
 
A simplified copy of my class is below. The update is fine, but the insert is not. I need to call "next insert()" before writing to "myCustomField" because I need the RecId to exist, but I think that since the CustTable "insert()" method ends with "ttscommit", my code isn't working. I've did the same on SalesTable, and it works. 
 
Could this be the reason, and does anyone have some pointers for me to solve this? 
 
[ExtensionOf(tableStr(CustTable))]
final class AB_CustTable_Table_Extension
{
    void insert(DirPartyType _partyType, Name _name, boolean _updateCRM)
    {
        next insert(_partyType, _name, _updateCRM);

	this.myCustomField = any2str(this.RecId) + "_" + this.someField + "_" + this.anotherField;
    }

    void update(boolean _updateSmmBusRelTable, boolean _updateParty)
    {
	this.myCustomField = any2str(this.RecId) + "_" + this.someField + "_" + this.anotherField;

        next update(_updateSmmBusRelTable, _updateParty);
    }

}
Thanks!
 
BR
Categories:
  • hca Profile Picture
    hca 96 on at
    CustTable insert() CoC get RecId
    We have several entities we are doing this for, and I had not checked the PowerAppsHost for one of them. I agree that was wrong configuration, but it's to my point about this way of doing it could be risky. I think it's a (big) bug that Finance have some sort of two way binding that let's the PowerAppsHost write data back to the table. We have no idea what's going on behind the scenes with this control, and for all I know, some poor table is getting updated without us knowing it now.
  • Martin Dráb Profile Picture
    Martin Dráb 230,655 Most Valuable Professional on at
    CustTable insert() CoC get RecId
    You need to decide whether you want it bound to a field or not. In your case, you want set the value directly, therefore having it bound to a data source is a mistake.
  • hca Profile Picture
    hca 96 on at
    CustTable insert() CoC get RecId
    As a warning to anyone who may read this information about the PowerAppsHost, if you have selected a data source and field in the PowerAppsHost, and you write to "EntityId" programmatically, the value gets written back to the data source. I cannot understand this as anything other than a bug in Finance, and a little scary I might add.
  • hca Profile Picture
    hca 96 on at
    CustTable insert() CoC get RecId
    Ok, thank you for clarifying that. I can confirm that it works.
  • Martin Dráb Profile Picture
    Martin Dráb 230,655 Most Valuable Professional on at
    CustTable insert() CoC get RecId
    In my opinion, setting the value directly is equally supported scenario as using a binding, therefore I don't see why you should be rejecting one of these solutions and promiting the other.
  • hca Profile Picture
    hca 96 on at
    CustTable insert() CoC get RecId
    Yes, I've tried experimenting. As I wrote in the other thread, it threw me down a rabbit whole with hours of amazing Finance errors :)
     
    As of now, since you warned us against the additional table field, we plan to set EntityId directly from a form event handler instead. The concern is that Finance might do something with that field after we write to it. We don't know what they might do in the future also.
     
    Thanks!
  • Martin Dráb Profile Picture
    Martin Dráb 230,655 Most Valuable Professional on at
    CustTable insert() CoC get RecId
    If I was you, I would simply try it and see if it works, I get an error (which tells me what I'm doing wrong) or so. For example, try a table method method accepting no parameters and returning a string. 
     
    Not everything is well-document, or behaves as documented. Experimenting is a integral part of my work as a developer. :-)
     
    Instead of binding to a data source, you could also set entityId directly from code.
  • hca Profile Picture
    hca 96 on at
    CustTable insert() CoC get RecId
    That's correct, I should be able to use that field, but I don't understand how to use it. I am not sure about the syntax, and when I try to point to a method, Finance doesn't find it. Probably because my syntax is wrong :) It would seem like it's the best option to point to a method that returns the entity ID, but I've yet to find any examples online on how to use it correctly.
  • Martin Dráb Profile Picture
    Martin Dráb 230,655 Most Valuable Professional on at
    CustTable insert() CoC get RecId
    The process I'm talking about is Embed canvas apps from Power Apps.
     
    In your case, you should be able to use Entity ID Method property. You mentioned you could't figure out how to use it, but didn't provide any details.
  • hca Profile Picture
    hca 96 on at
    CustTable insert() CoC get RecId
    This is getting a bit beyond the scope of this thread, but it says "Control name" when you click the drop down in your screenshot. I was under the impression that the available fields are coming from the OData exposed entity, so for Customer it would be the CustCustomerV3Entity. I could be wrong. But writing to the Power App that gets added via personalization via code seems even more complex to me. At the moment I'm working with the "PowerAppsHost" control, which exposes table fields directly. Hopefully we could support both, but it's not a must right now.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Share Your Event with the Community

Jump start your event engagement! 📢

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,938 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,655 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans