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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

c/al code review

(0) ShareShare
ReportReport
Posted on by 7

Hi all, 

we are trying to accomplish an automation where when the lifecycle stage of an item is in a specific stage and we have 0 qty on hand, o qty on order and the tier revision date is at least 2 weeks greater than our workdate we want to set the lifecycle stage to obsolete, check a box on our item card edi obsolete true, uncheck a box on our item card include on website and delete our item cross references for those items affected after 14 days.

additionally we have a need to uncheck default bins, fixed bins, and empty bins in the bin contents

our MS partner applied this object as a report to run however this is not doing anything after setting items to:

0 on hand in all locations

0 on purchase order

Compare date = at least 14 days from today’s date (07.30.19)

Tier revision date is set (07.30.19)

EDI obsolete is false

Include on website is true

I have tried setting my work date in nav to be in the future approximately 09.26.19 and running the item automation cleanup but I yield the same result.

Documentation()

OnInitReport()

OnPreReport()

OnPostReport()

Item - OnPreDataItem()
Item.CALCFIELDS(Inventory, "Qty. on Purch. Order","Qty. on Sales Order");
CompareDate := WORKDATE-14;

Item - OnAfterGetRecord()
Item."Lifecycle Stage" := 'OBSOLETE - DISC.';
Item."EDI Obsolete" := TRUE;
Item."Include on Website" := FALSE;
Item.MODIFY;
IF (Item."Tier Revision Date" < (CompareDate))
AND (Item."Tier Revision Date" > 0D)
AND (Item.Inventory = 0)
AND (Item."Qty. on Purch. Order"=0) THEN BEGIN
ItemCrossReference.RESET;
ItemCrossReference.SETRANGE("Item No.", Item."No.");
IF ItemCrossReference.FINDSET THEN
ItemCrossReference.DELETEALL(TRUE);
END;

Item - OnPostDataItem()
BinContent.RESET;
BinContent.SETRANGE(Default, TRUE);
IF BinContent.FINDSET THEN
BinContent.MODIFYALL(Default, FALSE);

BinContent.RESET;
BinContent.SETRANGE(Fixed, TRUE);
IF BinContent.FINDSET THEN
BinContent.MODIFYALL(Fixed, FALSE);

BinContent.CALCFIELDS(Quantity);
BinContent.SETRANGE(Quantity, 0);
IF BinContent.FINDSET THEN
BinContent.DELETEALL(TRUE);

can anyone confirm that this is the correct way to approach this?  what would need to change?

*This post is locked for comments

I have the same question (0)
  • ManishS Profile Picture
    86 on at

    I don't see any code where it check the qty on hand.

    This code should not be written (Item.CALCFIELDS(Inventory, "Qty. on Purch. Order","Qty. on Sales Order");, there is an property on report calcfield, there you can select the required calcfields, cause you are using item master as your dataitem.

    Also which bin content is getting deleted, cause I don't see any code written to set the item,location and then find the bin content.

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 June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans