Skip to main content

Notifications

Announcements

No record found.

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

Add order hold code to Sales order through X++

(1) ShareShare
ReportReport
Posted on by 47
I have a requirement to add an order hold code to a Sales Order when a credit card capture gets declined. In other words, upon a credit card authorization (CreditCardAuthTrans) entry in a /declined/ status getting inserted, I need to apply an order hold code to this sales order. I have been trying to get this to happen by inserting a hold code transaction (MCRHoldCodeTrans) for the sales order when a CreditCardAuthTrans) entry in a /declined/ status gets inserted (using event handlers, chain of command). I have tried a number of things posted below, and everytime I step through the code it appears to be correctly setting and inserting a MCRHoldCodeTrans, but when I query the database or check on the front end, it appears that nothing is happening. I even tried using doInsert() and this didn't work either. Has anyone ever seen anything like this, or have any ideas to try for this scenario? Thanks!
 
idea 1: insert MCRHoldCodeTrans on inserting event handler for CreditCardAuthTrans; I also tried this with the OnInsert event and it didn't work
 
 [DataEventHandler(tableStr(CreditCardAuthTrans), DataEventType::Inserting)]
    public static void CreditCardAuthTrans_onInserting(Common sender, DataEventArgs e)
    {
        CreditCardAuthTrans creditCardAuthTrans = sender as CreditCardAuthTrans;
        MCRHoldCodeTrans holdCodeTrans;
        CustParameters custParameters;
        select custParameters where custParameters.DataAreaId == 'rev';
        str declinedCCHoldCode = custParameters.revDeclinedCCOrderHoldCode;
        CreditCardProcessorStatus status = creditCardAuthTrans.ProcessorStatus;
        str salesId = creditCardAuthTrans.SalesId;
        
        if(creditCardAuthTrans.ProcessorStatus == CreditCardProcessorStatus::Declined)
        {
            ttsbegin;
            select forupdate holdCodeTrans;
            holdCodeTrans.initValue();
            holdCodeTrans.InventRefId = creditCardAuthTrans.SalesId;
            holdCodeTrans.MCRHoldCode = declinedCCHoldCode;
            holdCodetrans.RetailInfocodeId = 'HoldCode';
            holdCodeTrans.insert();
            ttscommit;
        }
    }
 
 
////Idea 2; Chain of Command on CreditCardAuthTrans.insert() but didn't work
 
 public void insert()
    {
      
        MCRHoldCodeTrans holdCodeTrans;
        CustParameters custParameters;
        select custParameters where custParameters.DataAreaId == 'rev';
        str declinedCCHoldCode = custParameters.revDeclinedCCOrderHoldCode;
        CreditCardProcessorStatus status = this.ProcessorStatus;
        str salesId = this.SalesId;
        
        if(this.ProcessorStatus == CreditCardProcessorStatus::Declined)
        {
            //ttsbegin;
            holdCodeTrans.InventRefId = this.SalesId;
            holdCodeTrans.MCRHoldCode = declinedCCHoldCode;
            holdCodetrans.RetailInfocodeId = 'HoldCode';
            holdCodeTrans.insert();
            //ttscommit;
        }
        next insert();
 
   [DataEventHandler(tableStr(CreditCardAuthTrans), DataEventType::Inserted)]    public static void CreditCardAuthTrans_onInserted(Common sender, DataEventArgs e)    {        CreditCardAuthTrans creditCardAuthTrans = sender as CreditCardAuthTrans;        MCRHoldCodeTrans holdCodeTrans;        CustParameters custParameters;        select custParameters where custParameters.DataAreaId == 'rev';        str declinedCCHoldCode = custParameters.revDeclinedCCOrderHoldCode;        CreditCardProcessorStatus status = creditCardAuthTrans.ProcessorStatus;        str salesId = creditCardAuthTrans.SalesId;                if(creditCardAuthTrans.ProcessorStatus == CreditCardProcessorStatus::Declined)        {            ttsbegin;            select forupdate holdCodeTrans;            holdCodeTrans.initValue();            holdCodeTrans.InventRefId = creditCardAuthTrans.SalesId;            holdCodeTrans.MCRHoldCode = declinedCCHoldCode;            holdCodetrans.RetailInfocodeId = 'HoldCode';            holdCodeTrans.insert();            ttscommit;        }    }/// Idea 2: CoC on CreditCardAuthTrans.insert()    public void insert()    {              MCRHoldCodeTrans holdCodeTrans;        CustParameters custParameters;        select custParameters where custParameters.DataAreaId == 'rev';        str declinedCCHoldCode = custParameters.revDeclinedCCOrderHoldCode;        CreditCardProcessorStatus status = this.ProcessorStatus;        str salesId = this.SalesId;                if(this.ProcessorStatus == CreditCardProcessorStatus::Declined)        {            //ttsbegin;            holdCodeTrans.InventRefId = this.SalesId;            holdCodeTrans.MCRHoldCode = declinedCCHoldCode;            holdCodetrans.RetailInfocodeId = 'HoldCode';            holdCodeTrans.insert();            //ttscommit;        }        next insert();/// Idea 3, event handler on inserting    [DataEventHandler(tableStr(CreditCardAuthTrans), DataEventType::Inserting)]    public static void CreditCardAuthTrans_onInserting(Common sender, DataEventArgs e)    {        CreditCardAuthTrans creditCardAuthTrans = sender as CreditCardAuthTrans;        MCRHoldCodeTrans holdCodeTrans;        CustParameters custParameters;        select custParameters where custParameters.DataAreaId == 'rev';        str declinedCCHoldCode = custParameters.revDeclinedCCOrderHoldCode;        CreditCardProcessorStatus status = creditCardAuthTrans.ProcessorStatus;        str salesId = creditCardAuthTrans.SalesId;                if(creditCardAuthTrans.ProcessorStatus == CreditCardProcessorStatus::Declined)        {            ttsbegin;            select forupdate holdCodeTrans;            holdCodeTrans.initValue();            holdCodeTrans.InventRefId = creditCardAuthTrans.SalesId;            holdCodeTrans.MCRHoldCode = declinedCCHoldCode;            holdCodetrans.RetailInfocodeId = 'HoldCode';            holdCodeTrans.insert();            ttscommit;        }    }
 
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 6,408 Super User 2024 Season 2 on at
    Add order hold code to Sales order through X++
     
    Remove  select forupdate holdCodeTrans; You want to insert a new record, it's wrong to do select statement. Try it and tell me the result.
     
    Regards,
    Waed Ayyad
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
     
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    Add order hold code to Sales order through X++
    That it reached ttscommit doesn't necessarily mean that the transaction was committed, because there may be an outer transaction. You'd need to pay attention to the transaction level.
     
    If the transaction isn't committed, you won't see the record in database, unless you explicitly ask for having uncommitted records included (e.g. WITH (NOLOCK) hint).
  • CU07051604-0 Profile Picture
    CU07051604-0 47 on at
    Add order hold code to Sales order through X++
    Hi Martin, 
     
    During debugging, I see the record with values set passing through the insert and ttscommit, and when I check the database at that time the record still hasn't landed in the table. It even has a recid and all required fields in the buffer when I am debugging. I am not sure how this is possible. I have tried full build and database synching as well.
  • Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    Add order hold code to Sales order through X++
    So the record to CreditCardAuthTrans is successfully inserted, your code in insert() (or CreditCardAuthTrans_onInserting()) is called and completes successfully, but either the record isn't actually inserted, or it's later deleted by something?
     
    Make sure that CreditCardAuthTrans is really inserted, we want to role out that the transaction wasn't rolled back.
     
    During debugging, you can check uncommitted data in database to see whether holdCodeTrans.insert() inserts a record and if so, when the record disappears again.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans