web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Add order hold code to Sales order through X++

(1) ShareShare
ReportReport
Posted on by
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;        }    }
 
I have the same question (0)
  • Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at
    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.
  • CU07051604-0 Profile Picture
    on at
    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
    237,948 Most Valuable Professional on at
    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).
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
     
    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
     
     
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans