Alternate way to run codeunit for update the custom field(Available Inventory) in item table.

Hi Everyone,[NAV 2009]

I have to update Custom field(Available inventory) of item table continuously. so, i created codeunit to run by jobqueue by every 5 min., but this activity became deadlock or this job became stop due to modifying anything in item table by another user.

My codeunit: with property: singleinstance=yes;

IF Item.FINDFIRST THEN

REPEAT
Item.CALCFIELDS(Inventory,"Qty. on Sales Order");
Item."Available Inventory" := Item.Inventory - Item."Qty. on Sales Order" - Item.Buffer;
Item.MODIFY;
UNTIL Item.NEXT = 0;

So, I tried to run codeunit directly by NAS.
for this I add code in codeunit:Application Management(1):

SRSetup.GET;
IF SRSetup."Run Available Inventory" THEN BEGIN
CODEUNIT.RUN(CODEUNIT::"NAS AvailableInventory_Kar");
MESSAGE('NAS Available Inventory Started');
END;

But ,this is now even updating the field. Once I restart the NAS-service,then only first time it use to update item table field after that not effecting. I check in Eventviewer,i am getting the MESSAGE 'NAS Available Inventory Started' as i put in codeunit 1 to run my codeunit.

Please check and guide me whether i am on right path or guide me further.
your help will be very-very appreciable..plse guide me.

Thanks,
Mani

Answers

  • ricardopaivaricardopaiva Member Posts: 14
    This seems so wrong. Are you sure you need to have that field and update it every 5 minutes?
    This will cause blocking for sure because you are updating all the records.
    If you really need to do this, then well least check if the Available Inventory needs to be updated and update only when needed.

    IF Item.FINDFIRST THEN

    REPEAT
    Item.CALCFIELDS(Inventory,"Qty. on Sales Order");
    IF Item.”Available Inventory” <> Item.Inventory - Item.”Qty. on Sales Order” - Item.Buffer THEN BEGIN
    Item."Available Inventory" := Item.Inventory - Item."Qty. on Sales Order" - Item.Buffer;
    Item.MODIFY;
    END;
    UNTIL Item.NEXT = 0;
  • ManiNavManiNav Member Posts: 120
    Hi ricardopaiva,

    Thanks for the guide. I will do the same as your suggestion and will update if it will work fine ie. without interruption.

    Thanks,
    Mani.
Sign In or Register to comment.