0

I want to set a default value based on curUserid() in PurchCreateOrder. How can I put data in my field on form extension ? Is there any better option of doing this ? Fields are bound to datasource and I have different fields with differentdatasources.

My code is giving me abnormal termination error with nullreferences. XPPCompiler

[ExtensionOf(tableStr(PurchTable))]

final class PurchCreateOrderGetDefAdress_Extension
{
void initvalue(PurchaseType  _purchaseType)
{
    next initvalue(_purchaseType);

    PurchTable purchtable;
    LogisticsPostalAddress logpostadress;
    UserInfoSz usrsz;
    str user = curUserId(); 


    select firstonly logpostadress where logpostadress.city == 'lub';
   // select firstonly InventSiteId, InventLocationId from purchtable join usrsz where purchtable.InventSiteId == usrsz.InventSiteId && usrsz.IsDefault == true;
    select firstonly InventSiteId from usrsz where usrsz.UserId == user && usrsz.IsDefault == true;

    purchtable.initValue();
    purchtable.deliveryname = 'asasasasas' ;//logpostadress.Address;
    purchtable.inventsiteid = usrsz.InventSiteId;
    purchtable.inventlocationid = usrsz.InventSiteId;


    info(strFmt("%1, %2, %3", logpostadress.Address, usrsz.InventSiteId));

}

}
Tweene
  • 257
  • 4
  • 16
  • I might be reading this wrong, but it looks like you're creating an endless loop by calling `purchtable.initValue();`? Your code is effectively inside `initValue()` calling `initValue()`. Shouldn't you use `this`? Take a look at https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/extensibility/method-wrapping-coc and at https://channel9.msdn.com/Blogs/mfp/X-Chain-Of-Command – Alex Kwitny Feb 20 '20 at 16:44
  • Even if I delete putchtable.initvalue my code dont work. Just get the error I mentioned above. When i tried it in formdatasourcestr im getting null references – Tweene Feb 20 '20 at 16:50

1 Answers1

0

The error is straight forward.

Error The augmented class 'PurchTable' provides a method by this name, but this method cannot be used as a chain of command method since the parameter profile does not match the original method.

Take a look at the highlighted parameter profile and compare to yours.

enter image description here

Edit: Take a look at these links for more info on Chain of Command (CoC):

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • Well after I added purchasetype without the def value .. public void initvalue(PurchaseType _purchaseType) I got abnormal termination error. – Tweene Feb 21 '20 at 07:26
  • Did you remove `purchtable.initValue();` as I mentioned in the other comment? You're in an endless loop. Start small and remove most of the code and just get `CoC` working correctly then add more code to identify what the error is. – Alex Kwitny Feb 21 '20 at 16:10
  • Even after I removed everything except CoC I get this problem. – Tweene Feb 21 '20 at 16:22
  • Did you review the links to ensure you're doing CoC correctly? If you only have the bare minimum CoC things, and you're saying it's not working, then it's either CoC is broken (doubtful) or there's something up with your environment or in another `initValue` call. Try full system build/sync. Just keep eliminating variables...right now you're just saying "it's not working" and we can't really help answer that. – Alex Kwitny Feb 21 '20 at 16:46
  • Well I tried to run it with just CoC in class and got abnormal termination error with like 40 error lines and had no idea what was broken ( the error what underlining only initvalue() mehod not the next call. I'll try to make a full model build still. By the time I did it with initvalue event handlers and it works quite well but I have a question there. When I have a field in form from another dbsource (LogisticsPostalAddress ) and I want to make a init there can I do it in 1 event ? Right now I needed to use 2 events for different tables. – Tweene Feb 21 '20 at 17:00