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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Suggested Answer

X++ code not triggering and working to submit the workflow.

(1) ShareShare
ReportReport
Posted on by 24

Hi,

Here is the requirement: I want to auto-submit the Purchase Requisition workflow through Power Automate based on a condition.

I attempted to create a new field in the PurchReqTable and added it to the PR form. After the creation of the PR and its line, I added the field I created (toggle: workflowautosubmit is yes) and added events like modified, enter, selection on changing. However, these events did not trigger during debugging.

Later, I tried to add the field in the PR Header entity, and through an extension, I attempted to add the ModifiedField method with the below code. However, it did not trigger even during debugging. Can you please correct my code and point out where I went wrong?

Thanks in advance for your reply.

code: 

[ExtensionOf(tableStr(PurchaseRequisitionHeaderV2Entity))]
final class PurchReqDataEntity_Extension
{
    public void modifiedField(FieldId _fieldId)
    {
    
        PurchaseRequisitionHeaderEntity purchReqHeaderEntity;
        PurchReqTable                 purchReqTable;
        purchReqHeaderEntity            = this;
       
       Select RecId from purchReqTable where purchReqTable.RequisitionNumber == purchReqHeaderEntity.RequistionNumber;
        if (purchReqTable.WorkFlowAutoSubmit == NoYes::Yes)
        {
            // activate and submit workflow
            Workflow::activateFromWorkflowType(workflowTypeStr(PurchReqReview),purchReqTable.RecId,/@Test:ProcurementPRReviewMeassage/,NoYes::No);
            purchReqTable.canSubmitToWorkflow(workflowTypeStr(PurchReqReview));
        }
    
        super(_fieldId);
    }
}
 
  • Martin Dráb Profile Picture
    241,360 Most Valuable Professional on at
    All the method you mentioned, including modifiedField(), are wrong for sure, but we can't say which method would be the right one without knowing what logic you're trying to implement.
     
    Do you want, for example, start a workflow after a new requisition was created (not on update of an existing one)?
  • Charan140 Profile Picture
    24 on at

    Thanks for your reply, Martin.
    Here I am creating a purchase requisition header and line with Power Automate (data comes from CRM), and after the creation of PR, I need to auto-submit the workflow. For that, I am choosing a field added in the entity and PR form in D365 fno; in Power Automate flow itself, after PR header and line creation, I am again updating that PR in the header for that field to submit the workflow. I tried different events and methods, and even the debugger didn't hit.

  • Martin Dráb Profile Picture
    241,360 Most Valuable Professional on at
    So what's answer about updates? Do you want an action only when inserting new record and you'll do nothing when existing records are updated?
  • Charan140 Profile Picture
    24 on at
    @Martin,
    The first step is to create the PR Header and PR Line. In the second step, grab the PR number from the first step, and fetch it with the PR Number and update the field in the PR field name: 'Workflow Auto Submit'  set to 'yes'. Only PRs meeting this condition should be submitted to the workflow.
     
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    307,719 Super User 2026 Season 2 on at
    Hi,
     
    In case you want to submit the PR to the workflow via OData, I would suggest implementing an OData action method instead of updating a field. On a data entity with the purchase requisition header as data source, you can then have the method with the logic for submitting the PR to the workflow. The method should be decorated with an attribute. E.g.
    /// <summary>
    /// Submits the purchase requisition to the workflow
    /// </summary>
    [SysODataActionAttribute('SubmitToWorkflow', true)]
    public void submitToWorkflow()
    {
        // Add the workflow activation logic here
    }
     
    You can read more about the action functionally and technically here: Let your Operations Flow – Part 8 - Dynamicspedia

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 109 Super User 2026 Season 2

#2
Laurens vd Tang Profile Picture

Laurens vd Tang 100 Super User 2026 Season 2

#3
Aayush Tiwari Profile Picture

Aayush Tiwari 56

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans