-2

EDIT: i am able to import using the code below, except now I have two very annoying issues: 1. The pair values are swapped in the custom table when there are multiple recipe IDs in the same file** 2. I am supposed to have 1 recipe ID for each bom and prod order that gets created through the HandleAlternateBOM function. Somehow I ended up with 339 prod orders and boms from 441 Recipe IDs. What did I do wrong?

Below is just the original post but no longer applies... {I am about to lose my mind trying to solve this issue. We have an XML port that's been working like clockwork, and an XML file that's been imported just minutes ago. We did modified the XML port but when we got an error on one of the parsing functions that we added, we immediately revert back to the original copy from backup.

So supposedly the XML port AND the XML file are same as before, then how can it be possible that the import now fails?

    It fails at a line of code that simply reads the inbound item number, and check to make sure it's in the correct format. The
format checking failed because the item number is now showing up as
blank value?

    Appreciate any insight.

** }

custom-attribute - Import::OnAfterAssignVariable()
//RecipeID := '' ;
EText1 := '';
EText2 := '';
IsPreSale := '';
TempAlternateBOM.RESET;
{
//AlternateBOM.SETCURRENTKEY("Recipe ID","Item No.","Variant Code","Location Code","Unit of Measure Code","Production BOM No.");
AlternateBOM.SETCURRENTKEY("Recipe ID","Item No.");
AlternateBOM.SETRANGE("Recipe ID",AlternateBOM."Recipe ID");
AlternateBOM.SETRANGE("Item No.",AlternateBOM."Item No.");
//AlternateBOM.SETRANGE("Variant Code",AlternateBOM."Variant Code");
AlternateBOM.SETFILTER("Location Code",'%1','1');
AlternateBOM.SETFILTER("Unit of Measure Code",'%1','EA');
AlternateBOM.SETFILTER("Production BOM No.",'<>%1','');
IF NOT AlternateBOM.FIND THEN BEGIN
}


WITH TempAlternateBOM DO BEGIN
"Item No." := ItemNo;

  CASE (Item_CustomAttributeID) OF
  'fluidConfigureRecipeID':
  BEGIN
    IF EVALUATE("Recipe ID",Item_CustomAttribute) AND (STRLEN(Item_CustomAttribute) > 1)
      THEN "Recipe ID" := Item_CustomAttribute;

    VALIDATE("Production BOM No.","Recipe ID");
TempAlternateBOM."Alternative Item No." := "Recipe ID";
    RecipeID := "Recipe ID";
"Variant Code" := VariantCode;
"Location Code" := '1';
TempAlternateBOM.INSERT(TRUE);
  END;
  'fluidConfigureResourceURL':
   "Recipe URL" :=Item_CustomAttribute;

  'fluidConfigureDnaBezelSKU':
    //IF EVALUATE("Bezel SKU",Item_CustomAttribute) THEN
      "Bezel SKU" := Item_CustomAttribute;
  'fluidConfigureDnaBandSKU':
   // IF EVALUATE("Band SKU",Item_CustomAttribute) THEN
      "Band SKU" := Item_CustomAttribute;
  'fluidConfigureDnaCaseSKU':
    //IF EVALUATE("Case SKU",Item_CustomAttribute) THEN
      "Case SKU" := Item_CustomAttribute;
  'fluidConfigureQuantity':
    EVALUATE(Quantity,Item_CustomAttribute);
  'fluidConfigurePrice':
    EVALUATE(Price,Item_CustomAttribute);
  'fluidConfigureResourceURL':
   "Recipe URL" :=Item_CustomAttribute;
  'isPreorder':
   BEGIN
    IF EVALUATE(TempAlternateBOM.Preorder,Item_CustomAttribute) THEN
      TempAlternateBOM.Preorder := Item_CustomAttribute;
      IF TempAlternateBOM.Preorder = 'true' THEN BEGIN
        TempSalesHeader."Sales Type Code" := 'PREORDER';
      END;
   END;
  'fluidConfigureDnaEngravingSKU':
    //IF EVALUATE("Engraving SKU",Item_CustomAttribute) THEN
      "Engraving SKU" := Item_CustomAttribute;
  'fluidConfigureDnaEngravingText1':
  //BEGIN
    //IF STRLEN(Item_CustomAttribute) <> 0 THEN
   // IF EVALUATE(TempAlternateBOM.EngravingText1,Item_CustomAttribute) THEN
 // END;
  'fluidConfigureDnaEngravingText2':
 // BEGIN
  ///  IF STRLEN(Item_CustomAttribute) <> 0 THEN
  //  IF EVALUATE(TempAlternateBOM.EngravingText2,Item_CustomAttribute) THEN
      TempAlternateBOM.EngravingText2 := Item_CustomAttribute;


 // END;

  'fluidConfigureImageURL':
   // IF EVALUATE("Image URL",Item_CustomAttribute) THEN
      "Image URL" := Item_CustomAttribute;

END;

TempAlternateBOM."Unit of Measure Code" := 'EA';
TempAlternateBOM."Created Date" := WORKDATE;
TempAlternateBOM."DWRE Order No." := OrderNo;
TempAlternateBOM."SO No." := SalesHeader."No.";

IF TempAlternateBOM."Recipe ID" <> '' THEN
 // TempAlternateBOM.MODIFY(TRUE);
   IF NOT TempAlternateBOM.INSERT(TRUE)
        THEN TempAlternateBOM.MODIFY(TRUE);


HandleAlternateBOMs;
//HandleProdBOM;

COMMIT;

END;
ClearFluidAttribute;

HandleAlternateBOMs function:

IF (TempAlternateBOM.FINDSET) AND (TempAlternateBOM."Recipe ID" <>  '') THEN BEGIN
  REPEAT
    AlternateBOM.INIT;

    AlternateBOM.VALIDATE("Item No.", TempAlternateBOM."Item No.");

    AlternateBOM.VALIDATE("Alternative Item No.", TempAlternateBOM."Alternative Item No.");

    AlternateBOM.VALIDATE("Variant Code", TempAlternateBOM."Variant Code");
    AlternateBOM.VALIDATE("Location Code", TempAlternateBOM."Location Code");
    //AlternateBOM.INSERT;
    AlternateBOM."Recipe ID" := TempAlternateBOM."Recipe ID";
    AlternateBOM."Production BOM No." := TempAlternateBOM."Production BOM No.";
    AlternateBOM."Created Date" := TempAlternateBOM."Created Date";


    //AlternateBOM.INSERT(TRUE);


   // AlternateBOM.VALIDATE("Alternate Item No.", TempAlternateBOM."Alternate Item No.");
    AlternateBOM."Unit of Measure Code" := TempAlternateBOM."Unit of Measure Code";
    AlternateBOM."DWRE Order No." := TempAlternateBOM."DWRE Order No.";
      AlternateBOM."SO No." := TempAlternateBOM."SO No.";
    AlternateBOM."Recipe URL" := TempAlternateBOM."Recipe URL";
    AlternateBOM."Case SKU" := TempAlternateBOM."Case SKU";
     AlternateBOM."Band SKU" := TempAlternateBOM."Band SKU";
      AlternateBOM."Bezel SKU" := TempAlternateBOM."Bezel SKU";
       AlternateBOM."Engraving SKU" := TempAlternateBOM."Engraving SKU";
        AlternateBOM.EngravingText1 := TempAlternateBOM.EngravingText1;
        AlternateBOM.EngravingText2 := TempAlternateBOM.EngravingText2;
    AlternateBOM."Image URL" := TempAlternateBOM."Image URL";
    AlternateBOM.Quantity := TempAlternateBOM.Quantity;
    AlternateBOM.Price := TempAlternateBOM.Price;
    AlternateBOM.Preorder := TempAlternateBOM.Preorder;




    IF NOT AlternateBOM.INSERT THEN
    AlternateBOM.MODIFY;

    UNTIL (TempAlternateBOM.NEXT = 0);


  //Create new BOM using Production BOM No. as No.
  ProdBOMHeader.RESET;
  ProdBOMHeader.SETRANGE("No.",AlternateBOM."Production BOM No.");
  IF NOT ProdBOMHeader.GET(AlternateBOM."Production BOM No.") THEN BEGIN
    ProdBOMHeader.INIT;
    ProdBOMHeader."No." := AlternateBOM."Production BOM No.";
    ProdBOMHeader.Status := ProdBOMHeader.Status::New;
    ProdBOMHeader.VALIDATE(Description,OrderNo + ' ' + AlternateBOM."Production BOM No.");
    ProdBOMHeader."Unit of Measure Code"  := 'EA';

    ProdBOMHeader.INSERT;

//Get Item No & Variant for Case SKU
// IF STRLEN(RecipeID) = 8 THEN

    ProdBOMLine.SETRANGE("Production BOM No.",AlternateBOM."Production BOM No.");

    IF NOT ProdBOMLine.FIND THEN BEGIN
      ProdBOMLine.INIT;
      ProdBOMLine."Production BOM No." := ProdBOMHeader."No.";
      //MESSAGE(ProdBOMHeader."No." + 'confirm');
      //MESSAGE(AlternateBOM."Case SKU");
      ProdBOMLine."Version Code" := '';
      ProdBOMLine."Line No." := 10000;
      ProdBOMLine.Type := ProdBOMLine.Type::Item;
      IF (STRPOS(AlternateBOM."Case SKU", '-') > 0) THEN
        CaseSKU := COPYSTR(AlternateBOM."Case SKU", 1, STRPOS(AlternateBOM."Case SKU", '-') - 1)
      ELSE
        ERROR('Case SKU is not in expected format. Value expected XXXX-YYY-ZZZ. Value received: %1', AlternateBOM."Case SKU");

      IF (CaseSKU <> '') THEN
        CaseVariant := COPYSTR(AlternateBOM."Case SKU", STRLEN(CaseSKU) + 2)
      ELSE
        ERROR('No item number provided!');

      ProdBOMLine.VALIDATE("No.",CaseSKU);
      ProdBOMLine.VALIDATE("Variant Code",CaseVariant);
      ProdBOMLine.VALIDATE("Quantity per",1);
      ProdBOMLine.INSERT(TRUE);
    END;



//Get Item No & Variant for Bezel SKU
    ProdBOMLine.SETRANGE("Production BOM No.",ProdBOMHeader."No.");
    IF ProdBOMLine.FINDLAST THEN BEGIN
      ProdBOMLine."Production BOM No." := ProdBOMHeader."No.";
      ProdBOMLine."Version Code" := '';
      ProdBOMLine."Line No." := 20000;
      ProdBOMLine.Type := ProdBOMLine.Type::Item;
      IF (STRPOS(AlternateBOM."Bezel SKU", '-') > 0) THEN
        BezelSKU := COPYSTR(AlternateBOM."Bezel SKU", 1, STRPOS(AlternateBOM."Bezel SKU", '-') - 1)
      ELSE
        ERROR('Bezel SKU is not in expected format. Value expected XXXX-YYY-ZZZ. Value received: %1', AlternateBOM."Bezel SKU");

      IF (BezelSKU <> '') THEN
        BezelVariant := COPYSTR(AlternateBOM."Bezel SKU", STRLEN(BezelSKU) + 2)
      ELSE
        ERROR('No item number provided!');

      ProdBOMLine.VALIDATE("No.",BezelSKU);
      ProdBOMLine.VALIDATE("Variant Code",BezelVariant);
      ProdBOMLine.VALIDATE("Quantity per",1);
      ProdBOMLine.INSERT(TRUE);
    END;

    //Get Item No & Variant for Band SKU
    ProdBOMLine.SETRANGE("Production BOM No.",ProdBOMHeader."No.");
    IF ProdBOMLine.FINDLAST THEN BEGIN
      ProdBOMLine."Production BOM No." := ProdBOMHeader."No.";
      ProdBOMLine."Version Code" := '';
      ProdBOMLine."Line No." := 30000;
      ProdBOMLine.Type := ProdBOMLine.Type::Item;
      IF (STRPOS(AlternateBOM."Band SKU", '-') > 0) THEN
        BandSKU := COPYSTR(AlternateBOM."Band SKU", 1, STRPOS(AlternateBOM."Band SKU", '-') - 1)
      ELSE
        ERROR('Band SKU is not in expected format. Value expected XXXX-YYY-ZZZ. Value received: %1', AlternateBOM."Band SKU");

      IF (BandSKU <> '') THEN
        BandVariant := COPYSTR(AlternateBOM."Band SKU", STRLEN(BandSKU) + 2)
      ELSE
        ERROR('No item number provided!');

      ProdBOMLine.VALIDATE("No.",BandSKU);
      ProdBOMLine.VALIDATE("Variant Code",BandVariant);
      ProdBOMLine.VALIDATE("Quantity per",1);
      ProdBOMLine.INSERT(TRUE);
    END;

    //Get Item No & Variant for Engraving SKU
    ProdBOMLine.SETRANGE("Production BOM No.",ProdBOMHeader."No.");
    IF ProdBOMLine.FINDLAST THEN BEGIN

      ProdBOMLine."Production BOM No." := ProdBOMHeader."No.";
      ProdBOMLine."Version Code" := '';
      ProdBOMLine."Line No." := 40000;
      ProdBOMLine.Type := ProdBOMLine.Type::Item;
      IF (STRPOS(AlternateBOM."Engraving SKU", '-') > 0) THEN
        EngravingSKU := COPYSTR(AlternateBOM."Engraving SKU", 1, STRPOS(AlternateBOM."Engraving SKU", '-') - 1)
      ELSE
        ERROR('Engraving SKU is not in expected format. Value expected XXXX-YYY-ZZZ. Value received: %1', AlternateBOM."Band SKU");

      IF (EngravingSKU <> '') THEN
        EngravingVariant := COPYSTR(AlternateBOM."Engraving SKU", STRLEN(EngravingSKU) + 2)
      ELSE
        ERROR('No item number provided!');

      ProdBOMLine.VALIDATE("No.",EngravingSKU);
      ProdBOMLine.VALIDATE("Variant Code",EngravingVariant);
      CASE ProdBOMLine."Variant Code" OF
      'E001*':
        ProdBOMLine.Description := AlternateBOM.EngravingText1;
      'E002*':
        BEGIN
        ProdBOMLine.Description := AlternateBOM.EngravingText1;
        ProdBOMLine."Description 2" := AlternateBOM.EngravingText2;
        END;
      'E003*..E022*':
        //ProdBOMLine.VALIDATE(Description,AlternateBOM.EngravingText1);
        ProdBOMLine."Description 2" := AlternateBOM."Image URL";
       //ELSE
        //ProdBOMLine.VALIDATE(Description,AlternateBOM."Image URL");
      //IF STRLEN(AlternateBOM.EngravingText1) > 1 THEN
      //  ProdBOMLine.VALIDATE(Description,AlternateBOM.EngravingText1);
      //ProdBOMLine.VALIDATE("Description 2",AlternateBOM.EngravingText2);
        END;
        ProdBOMLine.VALIDATE("Quantity per",1);
        ProdBOMLine.INSERT(TRUE);
       END;


    //Get Default phantom BOM
    ProdBOMLine.SETRANGE("Production BOM No.",ProdBOMHeader."No.");
    IF ProdBOMLine.FINDLAST THEN BEGIN

      ProdBOMLine."Production BOM No." := ProdBOMHeader."No.";
      ProdBOMLine."Version Code" := '';
      ProdBOMLine."Line No." := 50000;
      ProdBOMLine.Type := ProdBOMLine.Type::"Production BOM";

      ProdBOMLine.VALIDATE("No.",'DEFAULT');
      ProdBOMLine.VALIDATE("Quantity per",1);
      ProdBOMLine.INSERT(TRUE);
    END;



    ProdBOMLine.MODIFY;



ProdBOMHeader.Status := ProdBOMHeader.Status::Certified;
ProdBOMHeader.MODIFY;
END;


//Create new Production order using Recipe ID/Production BOM No. as key
//IF STRLEN(RecipeID) > 0 THEN BEGIN
  //MESSAGE(RecipeID);
  ProdOrder.SETRANGE("No.",AlternateBOM."Production BOM No.");
  IF NOT ProdOrder.FIND THEN BEGIN
    ProdOrder.INIT;
    ProdOrder.VALIDATE("No.",AlternateBOM."Production BOM No.");
    ProdOrder.Status := ProdOrder.Status::Released;
    ProdOrder."Source Type" := ProdOrder."Source Type"::Item;
    ProdOrder."Source No." := AlternateBOM."Item No.";
    ProdOrder."Source Variant Code" := AlternateBOM."Variant Code";
    ProdOrder.VALIDATE("Source No.");     //populate other fields
    ProdOrder.Description := OrderNo + ' ' + AlternateBOM."Production BOM No.";
    ProdOrder.Quantity := AlternateBOM.Quantity;
    ProdOrder."Due Date" := SalesHeader."Shipment Date";
    IF ProdOrder."Due Date" = 0D THEN
      ProdOrder."Due Date" := WORKDATE;
    ProdOrder."Location Code" := '1';
    ProdOrder."Bin Code" := 'CUSTOM';
    MFGSetup.GET;
    ProdOrder."Starting Time" := MFGSetup."Normal Starting Time";
    ProdOrder."Ending Time" := MFGSetup."Normal Ending Time";

    IF NOT ProdOrder.INSERT
      THEN ProdOrder.MODIFY;

   END;


END;
WSNoob
  • 33
  • 8

1 Answers1

0

If NAV 2009 R2 and you use a XMLPort I can imagine it uses RTC client in this case probably not take well the restore object for RTC client.

So if you restart de NAV Service and then try to run this XMLport works fine.

Jonathan Bravetti
  • 2,228
  • 2
  • 15
  • 29
  • Actually I should mention we are on Classic not RTC. – WSNoob Sep 28 '16 at 16:46
  • Ok, You mention that fails if the when read Item number and this have blank value. How is the format checking function? – Jonathan Bravetti Sep 28 '16 at 17:28
  • Here is the code for the xmlport. I found out it's because the Recipe ID value was null and thus the format check function blew up. But i was always able to read that recipe id from the inbound xml. What am I doing wrong? – WSNoob Sep 30 '16 at 15:41
  • This code is in `Item_CustomAttribute - Import::OnAfterAssignField`? because if before this is the reason why the value is null. – Jonathan Bravetti Sep 30 '16 at 15:59
  • As I mentioned before the code was reading values and updating my table just fine then all of a sudden it starts throwing an error because the recipe id is read as null though the XML file clearly shows a value for the custom attribute – WSNoob Sep 30 '16 at 18:40
  • If I use another version of the xmlport then it works just fine but the pair values that get written to the custom table is mismatch. For example for each recipe id there is a corresponding URL that goes with it. When there are multiple reciple IDs in the same xml file sometimes the URL for one shows up in another. Below is the code and an example. – WSNoob Sep 30 '16 at 18:44
  • This is an example of how the pair values get swapped (note recipe iD is swapped) – WSNoob Sep 30 '16 at 18:55
  • 27579769 A1167 2800-00 1 EA 27579769 27579769 https://api.retail.net/recipe/27580002?api-key 27580002 A1167 2800-00 1 EA 27580002 27580002 https://api.retail.net/recipe/27579769?api-key – WSNoob Sep 30 '16 at 18:57
  • I just c&p the working code and took out the original code to avoid confusion. My problem now is with the swapped values between two different IDs when written to the custom table as shown above. – WSNoob Sep 30 '16 at 19:13
  • You can see from the code that I am creating a BOM then a production order for each recipe ID. However, I have 439 Reciple IDs and onlly 336 production orders and boms created. What did I do wrong??? – WSNoob Sep 30 '16 at 19:13
  • Try to Change this `//Create new Production order using Recipe ID/Production BOM No. as key //IF STRLEN(RecipeID) > 0 THEN BEGIN //MESSAGE(RecipeID); ProdOrder.SETRANGE("No.",AlternateBOM."Production BOM No."); IF NOT ProdOrder.FIND THEN BEGIN` **for this** `//Create new Production order using Recipe ID/Production BOM No. as key ProdOrder.RESET; ProdOrder.SETRANGE("No.", AlternateBOM."Production BOM No."); IF NOT ProdOrder.FINDFIRST THEN BEGIN` – Jonathan Bravetti Sep 30 '16 at 19:51