Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Activate Change Management on POs Through X++

(0) ShareShare
ReportReport
Posted on by 89

Hi, 

I had a requirement to change a field on a PO during the time of confirmation, however, I had to toggle change management to "No' in order to update the field. I then want to change 'changerequestRequired' back to yes after I update the field, but I am getting an error "Changes to the document are only allowed in state Draft, because change management is activated". This is failing on the second update() line because change management has been set back to yes in the code, but won't update on the SQL table. After the code below, the field changerequestrequired is still set to No, when I desire it to be set to Yes. 

Any help is appreciated.

ttsbegin;
purchTableSelected.ChangeRequestRequired = NoYes::No;
purchTableSelected.CE_ApplyAttachment = NoYes::No;
purchTableSelected.update();
ttscommit;

ttsbegin;
purchTableSelected.selectForUpdate(true);
purchTableSelected.ChangeRequestRequired = NoYes::Yes;
purchTableSelected.update();
ttscommit;

next clicked();

  • Martin Dráb Profile Picture
    234,037 Most Valuable Professional on at
    RE: Activate Change Management on POs Through X++

    Wouldn't it be a solution if you skip business logic in update() by calling doUpdate() instead or using PurchTableSkipBusinessLogicContext?

    using (var purchTableSkipBusinessLogicContext = PurchTableSkipBusinessLogicContext::construct())
    {
    	purchTableSkipBusinessLogicContext.parmSkipUpdate(true);
    	purchTableSelected.CE_ApplyAttachment = NoYes::No;
    	purchTableSelected.update();
    }

    By the way, I see you've put your logic into a clicked(), which isn't a good idea. Business logic doesn't belong to form control methods and it's definititely not where order confirmation posting is done. Look at PurchPurchOrderJournalPost class instead.

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Product updates

Dynamics 365 release plans