Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

how to initialize field using chain of command

(0) ShareShare
ReportReport
Posted on by 920

hello, 

I add  new field in table the I want to  initialize this field using chain of command in class extension,

I add  code like this : 

[ExtensionOf(classStr(OutLogisticOrderOut))]
 final class OutLogisticOrderOut_Extension
{
    public void createDetLOLine(Envelope _envelope, EnvLOOut _envLOOut, Warehouse _warehouse, ExchangeLineInfo _lineInfo)
    {
        Common                  sourceLine;
        DetLOLineOut            detLOLineOut;
        SalesLine               salesLine;
        sourceLine = this.retrieveSourceLine(_lineInfo);
        salesLine = sourceLine;
        detLOLineOut.PrepackGroupId = salesLine.Code;
        next createDetLOLine( _envelope,  _envLOOut,  _warehouse,  _lineInfo);
    }

}

the method createDetLOLine() : insert data in the table DetOLLine : 

how can I use the chain of command  :  i  initialize the field after or befor the next()?

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: how to initialize field using chain of command

    Yes it will work. You are updating the value for custom field after the record get inserted in createDetLoLine method.

    But to be more specific you can follow the workaround which i have mentioned previously.

    Thanks,

    Girish S.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: how to initialize field using chain of command

    Thanks Girish ,

    I have another option , but I don't know if the logic is exact or no : 

    public void createDetLOLine(Envelope _envelope, EnvLOOut _envLOOut, Warehouse _warehouse,ExchangeLineInfo _lineInfo)
    {
    
            
            Common                  sourceLine;
            DetLOLineOut      detLOLineOut;
            SalesLine               salesLine;
            Detail           detail
            next createDetLOLine( _envelope,  _envLOOut,  _warehouse,  _lineInfo);
            sourceLine = this.retrieveSourceLine(_lineInfo);
            salesLine = sourceLine;
            select * from detail where detail.envelop == _envLOOut.envelop
            select * from detLOLineOut where detLOLineOut.envelop == detail.envelop
            if(detLOLineOut)
            {
                 ttsbegin;
                 detLOLineOut.PrepackGroupId = salesLine.EOLECodeBreak;
                 detLOLineOut.update();
                 ttscommit;
            }
                
    
            
        }
    }

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: how to initialize field using chain of command

    Yes you can, but somehow you need to bypass the call to standard createDetLoLine method and then call your custom method.

    Another option will be using inheritance concept - create a new class and extend the class which is having createDetLoLine method - just copy the code along with method name and add code to populate values to custom field also.

    Also keep in mind that you need to call the newly created class instead of parent class which is having createDetLoLine method. Meaning this class may be called somewhere or from the menu item. So you need to change that to your newly created class.

    Thanks,

    Girish S.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: how to initialize field using chain of command

    I can use the same code from the original method ,

    just I change the name of method and  insert the new field?

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: how to initialize field using chain of command

    Then I think it won't be possible to get the buffer and assign a value using COC since the buffer is declared inside the method.

    You can only access the variables in COC that is declared globally in the class.

    You need to think of other way like using init value or insert method of table as mentioned earlier.

    Thanks,

    Girish S.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: how to initialize field using chain of command

    yes,  its declared inside the method

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: how to initialize field using chain of command

    Is the buffer 'detLOLineOut" is declared globally or declared inside the method 'createDetLoLine'?

    I think its declared inside the method that's why you are getting the error.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: how to initialize field using chain of command

    intelli sense doesn't work

    also I must use this class to initialize field

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: how to initialize field using chain of command

    Check whether intelli sense is working - Just type the buffer name and see whether its showing any suggestion for that buffer.

    If that doesn't work then try adding the logic on table level insert or initValue method before next keyword.  But make sure you will have required values to assign it to your custom field.

    Thanks,

    Girish S.

  • BASMA Profile Picture
    BASMA 920 on at
    RE: how to initialize field using chain of command

    I do the build of model with synch , but the same error .

    the field existe in table.

    when I add declaration of buffer in COC I don't get the error

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans