Skip to main content

Notifications

Announcements

No record found.

Supply Chain Management forum
Suggested answer

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

Posted on by 19

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);
    }
}
 
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,349 Super User 2024 Season 2 on at
    X++ code not triggering and working to submit the workflow.
    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
  • Charan140 Profile Picture
    Charan140 19 on at
    X++ code not triggering and working to submit the workflow.
    @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.
     
  • Martin Dráb Profile Picture
    Martin Dráb 228,212 Most Valuable Professional on at
    X++ code not triggering and working to submit the workflow.
    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
    Charan140 19 on at
    X++ code not triggering and working to submit the workflow.

    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
    Martin Dráb 228,212 Most Valuable Professional on at
    X++ code not triggering and working to submit the workflow.
    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)?

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,349 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,212 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans