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, ...
Unanswered

Line workflow doesn't uddate header status

(1) ShareShare
ReportReport
Posted on by 41
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:
I have the same question (0)
  • SM-28041246-0 Profile Picture
    41 on at
    i want to add that this method is inside my header table 
  • Martin Dráb Profile Picture
    237,996 Most Valuable Professional on at
    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.
  • André Arnaud de Calavon Profile Picture
    301,231 Super User 2025 Season 2 on at
    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? 
  • SM-28041246-0 Profile Picture
    41 on at

    I have only workflows on the lines 
  • André Arnaud de Calavon Profile Picture
    301,231 Super User 2025 Season 2 on at
    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? 
  • Martin Dráb Profile Picture
    237,996 Most Valuable Professional on at
    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;
        }
    }

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
Abhilash Warrier Profile Picture

Abhilash Warrier 669 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 384 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans