Check Item exist in Stockkeeping Unit

Hi Everybody.

I want check Item exits on table Stockkeeping Unit (ID 5700) If not exist then error.

I wrote the code below. But it can not be filtered for the case

SETFILTER(“Gen. Prod. Posting Group”,‘POS’); //on Sales Line


Quantity - OnValidate()
SkuItem.RESET;
Rec.RESET;
SETFILTER("Document Type",'%1',"Document Type"::Order);
SETFILTER("Gen. Prod. Posting Group",'POS');
SETFILTER(Type,'Item');
SkuItem.SETRANGE("Item No.","No.");
SkuItem.SETRANGE("Location Code","Location Code");
  IF SkuItem.ISEMPTY THEN
    ERROR('Stockkeeping Unit %1 not found in Location Code %2',"No.","Location Code");

Please help me solution, to fix this case. Thanks so much

Best Regards,

dinhson

Hi dinhson
Quantity - OnValidate()
SkuItem.RESET;
Rec.RESET;
SETFILTER(“Document Type”,’%1’,“Document Type”::Order);
SETFILTER(“Gen. Prod. Posting Group”,‘POS’);
SETFILTER(Type,‘Item’);
SkuItem.SETRANGE(“Item No.”,“No.”);
SkuItem.SETRANGE(“Location Code”,“Location Code”);
if not skuitem.findset then
ERROR(‘Stockkeeping Unit %1 not found in Location Code %2’,“No.”,“Location Code”);

try it.

Hi Gary
After the change. It has endless loop, and leads to crashes => Not work

Hi Dinhson.
why there is need “Rec.reset”?

Hi Gary,

After clear Rec.Reset
I still can not stop this SETFILTER(“Gen. Prod. Posting Group”,‘POS’);

I don’t understand where do you put this code ?
"SETFILTER(“Gen. Prod. Posting Group”,‘POS’); //on Sales Line "
and what do you want ? you need to stop setfilter ? if does, you need put setfilter on if condition.

Quantity - OnValidate()
SkuItem.RESET;

SkuItem.SETRANGE(“Item No.”,“No.”);
SkuItem.SETRANGE(“Location Code”,“Location Code”);
if not skuitem.findset then
ERROR(‘Stockkeeping Unit %1 not found in Location Code %2’,“No.”,“Location Code”);

SETFILTER(“Document Type”,’%1’,“Document Type”::Order);
SETFILTER(“Gen. Prod. Posting Group”,‘POS’);
SETFILTER(Type,‘Item’);

Hi Gary

Purpose I need to filter the Item code which has “Gen. Prod. Posting Group”=POS.
Other Item code is <> “Gen. Prod. Posting Group”=POS then not filtered

Can you describe it more clearly? which table?, which field ? which requirement ?

Hi Gary

I want to check on Sales Line (ID:37) compared with Stockkeeping Unit (ID 5700)
condition :
"Stockkeeping Unit ".SETRANGE(“Item No.”,“Sales Line”.“No.”);
"Stockkeeping Unit ".SETRANGE(“Location Code”,“Sales Line”.“Location Code”);
“Sales Line”.SETFILTER(“Sales Line”.“Gen. Prod. Posting Group”,‘POS’);

When “Item Code” not in the table Stockkeeping Unit (ID 5700) will be warning or Error.

Please help me. Thanks so much.

Hi Dinhson, where do you want to put this logic on ?

Hi Gary

I wan’t put in Quantity - OnValidate() after the user enter the Quantity.

If you want to check the condition when create a sales line, just need to put this check on “No.” Validate :
if “Sales line”.“Gen. Prod. Posting Group” = ‘POS’ then Begin
"Stockkeeping Unit ".SETRANGE(“Item No.”,“Sales Line”.“No.”);
"Stockkeeping Unit ".SETRANGE(“Location Code”,“Sales Line”.“Location Code”);
if NOT "Stockkeeping Unit ".findset then
ERROR(‘Stockkeeping Unit %1 not found in Location Code %2’,“No.”,“Location Code”);
End;

Hope it is helpfull. cheers.

Thanks you Gary. It’s work

But i put in code to Location Code - OnValidate() Because when input Item No then Location Code = blank.
required me to add the code Location Code - OnValidate()

Dear Gary.

WIth code above. I added two test conditions on the Item Code

ItemRec.SETFILTER(“Costing Method”,’%1’,ItemRec.“Costing Method”::Standard);
ItemRec.SETFILTER(“Inventory Value Zero”,’%1’,FALSE);

And write code again. But it’s not work. Please help me.


Rec.RESET;
SkuItem.RESET;
ItemRec.RESET;
SETFILTER(Type,'>0');
ItemRec.SETFILTER("Costing Method",'%1',ItemRec."Costing Method"::Standard);
ItemRec.SETFILTER("Inventory Value Zero",'%1',FALSE);
SkuItem.SETRANGE("Item No.",ItemRec."No.","No.");
SkuItem.SETRANGE("Location Code","Location Code");
SkuItem.SETRANGE("Item No.","No.");
    IF NOT SkuItem.FINDSET THEN
      ERROR('Stockkeeping Unit %1 not found in Location Code %2',"No.","Location Code");

Thank so much

Hi Dinhson,

Those filters (in ItemRec) do not affect to SkuItem var… The problem is that I don’t understand why you do all other filters.

To check if there are some rec in SkuItem, is enought do this (if you don’t need to do anything with SkuItem):

SkuItem.SETRANGE("Location Code","Location Code");
SkuItem.SETRANGE("Item No.","No.");
IF SkuItem.ISEMPTY THEN
  ERROR('Stockkeeping Unit %1 not found in Location Code %2',"No.","Location Code");

Hi Llaneras,

ItemRec is table Item (ID-27)

I want to filter the item conditional :

  • Item it’s : “Costing Method”=Standard Or “Inventory Value Zero” = FALSE

Item have other conditions will not filter. Because I have use the “Cost Method” item = Average. Item does not have SKU on Location Code.

Thanks so much.

Then you are some confusing using filters and conditions. You have to get item and then check if you need to test availability:

IF Type = Type::Item THEN BEGIN
  ItemRec.GET("No.");
  IF (ItemRec."Costing Method" = ItemRec."Costing Method"::Standard) AND
     (NOT ItemRec."Inventory Value Zero") THEN BEGIN
    SkuItem.RESET;
    SkuItem.SETRANGE("Location Code","Location Code");
    SkuItem.SETRANGE("Item No.","No.");
    IF SkuItem.ISEMPTY THEN
      ERROR('Stockkeeping Unit %1 not found in Location Code %2',"No.","Location Code");
  END;
END;

Hi Llaneras,

Thanks you. It’s work