Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Can't complete work on salesOrder using X++ code, WHSWorkManualComplete, workTable

(0) ShareShare
ReportReport
Posted on by 5

Hello.

I am having  problem completing Work on WHS (storage). I have salesOrder that have this work with two lines:

81638.png

Two lines of work has sttaus Opened. Then I executing this code on X

    ttsBegin;
    
    select workTable where workTable.OrderNum==salesTable.SalesId;

    info("workTable="   workTable.WorkBuildId);
    
    manualComplete = new WHSWorkManualComplete();

    while select forUpdate workLine where workLine.WorkId == workTable.WorkId && workLine.WorkStatus == WHSWorkStatus::Open {
        workLine.WorkStop = true;
        workLine.update();
    }

    setWorkHeaders.add(workTable);

    workCompleteForm.initFromSet(setWorkHeaders, tmpCompleteWorkTable, tmpCompleteWorkLine, true);
    
    while select tmpCompleteWorkLine {
        info("tmpCompleteWorkLine **"   int642str(tmpCompleteWorkLine.RecId));
    }
        
    if (manualComplete.validateWork(workTable.WorkCreatedBy, tmpCompleteWorkTable, tmpCompleteWorkLine)) {
        info("Validated work");

        while select forUpdate tmpCompleteWorkLine {
            info("tmpCompleteWorkLine **");
        }

        while select tmpCompleteWorkTable {
            manualComplete.executeWork(workTable.WorkCreatedBy, tmpCompleteWorkTable, tmpCompleteWorkLine);
                
            info("** manualComplete.executeWork ** ");
        }
    }

    delete_from tmpCompleteWorkTable;
    
    ttsCommit;

    info("Completado trabajo");

I executing this code and this is what I got:

1715.png

This is how WHS work looks like now:

4885.png

As you can see only first line is Closed, and second has same status Opened. I need to both lines to be Closed.

Can anyone help me with my X code, is anything incorrect?

Thanks.

  • Suggested answer
    Ruben Nys Profile Picture
    Ruben Nys 2 on at
    Can't complete work on salesOrder using X++ code, WHSWorkManualComplete, workTable
    Hi Alexeyfressko,
     
    EDIT: After further search, my answer is incorrect. It should work the way you have it programmed

    Your manualComplete.executeWork(..) method sits in a while select over the tmpCompleteWorkTable instead of the tmpCompleteWorkLine.
    Since there is only 1 tmpCompleteWorkTable , the code will only be executed once: for the first tmpCompleteWorkLine.
     
    If you change the table used in the while loop to tmpCompleteWorkLine, it should work for both lines.
  • Suggested answer
    RE: Can't complete work on salesOrder using X++ code, WHSWorkManualComplete, workTable

    Hi alexeyfressko,

    If you still need assistance on reported behavior, please open a support case with Microsoft support  and we will try helping you with this.

  • alexeyfressko Profile Picture
    alexeyfressko 5 on at
    RE: Can't complete work on salesOrder using X++ code, WHSWorkManualComplete, workTable

    Hi,

    At what part of X++ code I need to add RecID?

  • RE: Can't complete work on salesOrder using X++ code, WHSWorkManualComplete, workTable

    Hello Alexeyfressko,

    Can you add RecId to the line ? I do not see it now and it would be easier to understand.

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans