Skip to main content
Community site session details

Community site session details

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

Line workflow doesn't uddate header status

(1) ShareShare
ReportReport
Posted on by 22
I have done a workflow in my project, but I have a problem the header status doesn't change to "closed" if all the lines are approved for example it remains "open"
here is the method that is supposed to update the status:

 
 public void updateHeaderStatus()
 {
     boolean allProcessed = true;
     ITRequestEqLine itRequestEqLine;

     while select Status from itRequestEqLine
     where itRequestEqLine.ITRequestId == this.ITRequestId
     {
         if (itRequestEqLine.Status == WorkflowLineStatusCFM::InReview
      || itRequestEqLine.Status == WorkflowLineStatusCFM::Draft)
         {
             allProcessed = false;
             break;
         }
     }

     ITRequestEqHeader header;
     select forUpdate header where header.ITRequestId == this.ITRequestId;
     if (header.RecId)
     {
         ttsBegin;
         header.Status = allProcessed ? WorkflowHeaderStatusCFM::Closed : WorkflowHeaderStatusCFM::Open;
         header.update(); 
         ttsCommit;
     }
 }

and here is where is call it in workflow type event handler :

 
public class CFM_ITRequestEqTypeEventHandler implements
WorkflowCanceledEventHandler,
    WorkflowCompletedEventHandler,
    WorkflowStartedEventHandler
{
    public void started(WorkflowEventArgs _workflowEventArgs)
    {
        RecId recId = _workflowEventArgs.parmWorkflowContext().parmRecId();
        ITRequestEqLine::updateWorkflowStatus(recId, WorkflowLineStatusCFM::InReview);
    }
    public void canceled(WorkflowEventArgs _workflowEventArgs)
    {
        this.updateLineAndHeaderStatus(
            _workflowEventArgs.parmWorkflowContext().parmRecId(),
            WorkflowLineStatusCFM::Canceled
        );
    }
    public void completed(WorkflowEventArgs _workflowEventArgs)
    {
        this.updateLineAndHeaderStatus(
            _workflowEventArgs.parmWorkflowContext().parmRecId(),
            WorkflowLineStatusCFM::Approved
        );
    }
    private void updateLineAndHeaderStatus(RecId _lineRecId, WorkflowLineStatusCFM _status)
    {
        ITRequestEqLine::updateWorkflowStatus(_lineRecId, _status);
        ITRequestEqLine line = ITRequestEqLine::findRecId(_lineRecId);
        if (line.RecId && line.ITRequestId)
        {
            ITRequestEqHeader header;
            select firstOnly forUpdate header
                where header.ITRequestId == line.ITRequestId;
            if (header.RecId)
            {
                header.updateHeaderStatus(); // This will also use tts inside
            }
        }
    }
}
Categories:
  • Martin Dráb Profile Picture
    234,712 Most Valuable Professional on at
    Line workflow doesn't uddate header status
    Just by the way, we could make updateHeaderStatus() simpler and more efficient. Most importantly, you don't have to load all lines from database to check if there is an open line; you can ask the database to do the filtering and just give you the result.
     
    Therefore I would replace this:
    public void updateHeaderStatus()
    {
        boolean allProcessed = true;
        ITRequestEqLine itRequestEqLine;
    
        while select Status from itRequestEqLine
        where itRequestEqLine.ITRequestId == this.ITRequestId
        {
            if (itRequestEqLine.Status == WorkflowLineStatusCFM::InReview
         || itRequestEqLine.Status == WorkflowLineStatusCFM::Draft)
            {
                allProcessed = false;
                break;
            }
        }
    
        ITRequestEqHeader header;
        select forUpdate header where header.ITRequestId == this.ITRequestId;
        if (header.RecId)
        {
            ttsBegin;
            header.Status = allProcessed ? WorkflowHeaderStatusCFM::Closed : WorkflowHeaderStatusCFM::Open;
            header.update(); 
            ttsCommit;
        }
    }
    with something like this:
    protected void updateHeaderStatus()
    {
        // Is there any open line?
        ITRequestEqLine requestEqLineOpen;
        select firstonly RecId from requestEqLineOpen
            where requestEqLineOpen.ITRequestId == itRequestId
               && ( requestEqLineOpen.Status == WorkflowLineStatusCFM::InReview
                 || requestEqLineOpen.Status == WorkflowLineStatusCFM::Draft));
        
        if (!requestEqLineOpen.RecId)
        {
            // Mark the header closed
            ttsbegin;
            ITRequestEqHeader header = ITRequestEqHeader::find(itRequestId, true);
            header.Status = WorkflowHeaderStatusCFM::Closed;
            header.update();
            ttscommit;
        }
    }
  • André Arnaud de Calavon Profile Picture
    296,161 Super User 2025 Season 1 on at
    Line workflow doesn't uddate header status
    Have you used the debugger to check if your coding is being executed correctly?
     
    When you use the wizard when creating a new workflow type, it also creates several classes with outcommented coding to be implemented by you. Have you tried calling your header update logic from one of these classes? 
  • SM-28041246-0 Profile Picture
    22 on at
    Line workflow doesn't uddate header status

    I have only workflows on the lines 
  • André Arnaud de Calavon Profile Picture
    296,161 Super User 2025 Season 1 on at
    Line workflow doesn't uddate header status
    Hi,
     
    Can you tell us more about the workflow configuration in your environment? Do you have a workflow and line-item workflow or only workflows on the lines? 
  • Martin Dráb Profile Picture
    234,712 Most Valuable Professional on at
    Microsoft dynamics 365 f&o issue
    Please stop giving your threads the title Microsoft dynamics 365 f&o issue - it's too vague to be useful. Let me change it to Line workflow doesn't update header status, for instance.
     
    Also, ask question about F&O in F&O forums. Let me move this thread to Finance | Project Operations, Human Resources, AX, GP, SL forum.
  • SM-28041246-0 Profile Picture
    22 on at
    Microsoft dynamics 365 f&o issue
    i want to add that this method is inside my header table 

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June 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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565

#2
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 402 Super User 2025 Season 1

Product updates

Dynamics 365 release plans