Options

How do you debug this?

ara3nara3n Member Posts: 9,255
Why would you write code like this and how do you debug this?
IF CalculatedCorrectly2 AND
         ((RFStatEntryTotal2."Outstanding Quantity" <> 0) OR
           RFEmployeeSetup."Ignore Action Outst. Qty of 0") AND
         ((RFStatEntryTotal2."Available Volume" >=
             OutboundWhseRequestFilter."Minimum Avail. Volume") AND
          ((RFStatEntryTotal2."Available Volume" <=
             OutboundWhseRequestFilter."Maximum Avail. Volume") OR
           (OutboundWhseRequestFilter."Maximum Avail. Volume" = 0))) AND
         ((RFStatEntryTotal2."Available Gross Weight" >=
             OutboundWhseRequestFilter."Minimum Avail. Gross Weight") AND
          ((RFStatEntryTotal2."Available Gross Weight" <=
             OutboundWhseRequestFilter."Minimum Avail. Gross Weight") OR
           (OutboundWhseRequestFilter."Maximum Avail. Gross Weight" = 0))) AND
         ((RFStatEntryTotal2."Net Weight (Base)" >=
             OutboundWhseRequestFilter."Minimum Avail. Net Weight") AND
          ((RFStatEntryTotal2."Net Weight (Base)" <=
             OutboundWhseRequestFilter."Maximum Avail. Net Weight") OR
           (OutboundWhseRequestFilter."Maximum Avail. Net Weight" = 0))) AND
         ((RFStatEntryTotal2."Available Qty. (Base)" >=
             OutboundWhseRequestFilter."Minimum Avail. Qty. (Base)") AND
          ((RFStatEntryTotal2."Available Qty. (Base)" <=
             OutboundWhseRequestFilter."Maximum Avail. Qty. (Base)") OR
           (OutboundWhseRequestFilter."Maximum Avail. Qty. (Base)" = 0))) AND
         ((RFStatEntryTotal2."Available Amount" >=
             OutboundWhseRequestFilter."Minimum Avail. Amount") AND
          ((RFStatEntryTotal2."Available Amount" <=
             OutboundWhseRequestFilter."Maximum Avail. Amount") OR
           (OutboundWhseRequestFilter."Maximum Avail. Amount" = 0))) AND
         ((RFStatEntryTotal2."Outstanding No. of Lines" >=
             OutboundWhseRequestFilter."Minimum Outst. No. of Lines") AND
          ((RFStatEntryTotal2."Outstanding No. of Lines" <=
             OutboundWhseRequestFilter."Maximum Outst. No. of Lines") OR
           (OutboundWhseRequestFilter."Maximum Outst. No. of Lines" = 0))) AND
         (((ValueType = 0) AND (RFStatEntryTotal2."Outstanding Quantity" <> 0)) OR
          ((ValueType = 1) AND (RFStatEntryTotal2."Available Quantity" <> 0)) OR
          ((ValueType = 2) AND (RFStatEntryTotal2."Total Available Quantity" <> 0)) OR
          ((ValueType = 3) AND
           (RFStatEntryTotal2."Outstanding Quantity" = RFStatEntryTotal2."Available Quantity")) OR
          ((ValueType = 4) AND
           (RFStatEntryTotal2."Total Available Quantity" > RFStatEntryTotal2."Available Quantity"))) OR
          ((ValueType = 5) AND (RFStatEntryTotal2."Inv. Reserved Quantity" <> 0)) OR
          ((ValueType = 6) AND
           (RFStatEntryTotal2."Outstanding Quantity" <> 0) AND
           (RFStatEntryTotal2.Quantity = RFStatEntryTotal2."Outstanding Quantity")) OR
          ((ValueType = 7) AND
           (RFStatEntryTotal2."Outstanding Quantity" <> 0) AND
           (WarehouseRequestTmp."Shipment Date" < WORKDATE)) OR
          ((ValueType = 8) AND
           (RFStatEntryTotal2."ATO Quantity" <> 0)) OR
          ((ValueType = 10) AND
           (RFStatEntryTotal2."Outstanding No. of Lines" = 1) AND
           (RFStatEntryTotal2."Outstanding Quantity" <> 0)) OR
          ((ValueType = 11) AND
           (RFStatEntryTotal2."Outstanding No. of Lines" = 1) AND
           (RFStatEntryTotal2."Available Quantity" <> 0)) OR
          ((ValueType = 12) AND
           (RFStatEntryTotal2."Outstanding No. of Lines" = 1) AND
           (RFStatEntryTotal2."Total Available Quantity" <> 0)) OR
          ((ValueType = 13) AND
           (RFStatEntryTotal2."Outstanding No. of Lines" = 1) AND
           (RFStatEntryTotal2."Outstanding Quantity" = RFStatEntryTotal2."Available Quantity")) OR
          ((ValueType = 14) AND
           (RFStatEntryTotal2."Outstanding No. of Lines" = 1) AND
           (RFStatEntryTotal2."Total Available Quantity" > RFStatEntryTotal2."Available Quantity")) OR
          ((ValueType = 15) AND
           (RFStatEntryTotal2."Outstanding No. of Lines" = 1) AND
           (RFStatEntryTotal2."Inv. Reserved Quantity" <> 0)) OR
          ((ValueType = 16) AND
           (RFStatEntryTotal2."Outstanding No. of Lines" = 1) AND
           (RFStatEntryTotal2."Outstanding Quantity" <> 0) AND
           (RFStatEntryTotal2.Quantity = RFStatEntryTotal2."Outstanding Quantity")) OR
          ((ValueType = 17) AND
           (RFStatEntryTotal2."Outstanding No. of Lines" = 1) AND
           (RFStatEntryTotal2."Outstanding Quantity" <> 0) AND
           (WarehouseRequestTmp."Shipment Date" < WORKDATE)) OR
          ((ValueType = 18) AND
           (RFStatEntryTotal2."Outstanding No. of Lines" = 1) AND
           (RFStatEntryTotal2."ATO Quantity" <> 0))
      THEN BEGIN
Ahmed Rashed Amini
Independent Consultant/Developer


blog: https://dynamicsuser.net/nav/b/ara3n

Answers

  • Options
    TallyHoTallyHo Member Posts: 383
    Crazy!!
  • Options
    TallyHoTallyHo Member Posts: 383
    I'd debug this writing all separate boolean outcomes to a textfile or message
  • Options
    aceXaceX Member Posts: 166
    Is this AI programmed in NAV? :o
  • Options
    DuikmeesterDuikmeester Member Posts: 304
    Without completely refactoring this Brainf*ck

    Remove the third closing bracket the following line
    (RFStatEntryTotal2."Total Available Quantity" > RFStatEntryTotal2."Available Quantity"))) OR
    
    like this
    (RFStatEntryTotal2."Total Available Quantity" > RFStatEntryTotal2."Available Quantity")) OR
    

    and add a third closing bracket the last line
    (RFStatEntryTotal2."ATO Quantity" <> 0))
    
    like this
    (RFStatEntryTotal2."ATO Quantity" <> 0)))
    
  • Options
    DuikmeesterDuikmeester Member Posts: 304
    edited 2019-06-28
    Noticed there might not be a ValueType 9
    OnRun()
    IF CalculatedCorrectly2 AND 
       CheckOutstandingQuantity AND 
       CheckAvailableVolume AND 
       CheckAvailableGrossWeight AND
       CheckNetWeight AND
       CheckAvailableQty AND
       CheckAvailableAmount AND
       CheckOutstandingNoOfLines AND
       CheckValueType
    THEN BEGIN
    END;
    
    LOCAL CheckOutstandingQuantity() : Boolean
    EXIT(
      (RFStatEntryTotal2."Outstanding Quantity" <> 0)
    OR 
      RFEmployeeSetup."Ignore Action Outst. Qty of 0"
    );
    
    LOCAL CheckAvailableVolume() : Boolean
    EXIT(IsBetweenMinMax(RFStatEntryTotal2."Available Volume",
                         OutboundWhseRequestFilter."Minimum Avail. Volume",
                         OutboundWhseRequestFilter."Maximum Avail. Volume"));
    
    LOCAL CheckAvailableGrossWeight() : Boolean
    EXIT(IsBetweenMinMax(RFStatEntryTotal2."Available Gross Weight",
                         OutboundWhseRequestFilter."Minimum Avail. Gross Weight",
                         OutboundWhseRequestFilter."Maximum Avail. Gross Weight"));
    
    LOCAL CheckNetWeight() : Boolean
    EXIT(IsBetweenMinMax(RFStatEntryTotal2."Net Weight (Base)",
                         OutboundWhseRequestFilter."Minimum Avail. Net Weight",
                         OutboundWhseRequestFilter."Maximum Avail. Net Weight"));
    
    LOCAL CheckAvailableQty()
    EXIT(IsBetweenMinMax(RFStatEntryTotal2."Available Qty. (Base)",
                         OutboundWhseRequestFilter."Minimum Avail. Qty. (Base)",
                         OutboundWhseRequestFilter."Maximum Avail. Qty. (Base)"));
    
    LOCAL CheckAvailableAmount() : Boolean
    EXIT(IsBetweenMinMax(RFStatEntryTotal2."Available Amount",
                         OutboundWhseRequestFilter."Minimum Avail. Amount",
                         OutboundWhseRequestFilter."Maximum Avail. Amount"));
    
    LOCAL CheckOutstandingNoOfLines() : Boolean
    EXIT(IsBetweenMinMax(RFStatEntryTotal2."Outstanding No. of Lines",
                         OutboundWhseRequestFilter."Minimum Outst. No. of Lines",
                         OutboundWhseRequestFilter."Maximum Outst. No. of Lines"));
    
    LOCAL CheckValueType() : Boolean
    CASE ValueType OF
      0: 
        EXIT(RFStatEntryTotal2."Outstanding Quantity" <> 0);
      1:
        EXIT(RFStatEntryTotal2."Available Quantity" <> 0);
      2:
        EXIT(RFStatEntryTotal2."Total Available Quantity" <> 0);
      3:
        EXIT(RFStatEntryTotal2."Outstanding Quantity" = RFStatEntryTotal2."Available Quantity");
      4:
        EXIT(RFStatEntryTotal2."Total Available Quantity" > RFStatEntryTotal2."Available Quantity");
      5:
        EXIT(RFStatEntryTotal2."Inv. Reserved Quantity" <> 0);
      6:
        EXIT(  
          (RFStatEntryTotal2."Outstanding Quantity" <> 0) 
        AND 
          (RFStatEntryTotal2.Quantity = RFStatEntryTotal2."Outstanding Quantity")
        );
      7:
        EXIT(
          (RFStatEntryTotal2."Outstanding Quantity" <> 0) 
        AND 
          (WarehouseRequestTmp."Shipment Date" < WORKDATE)
        );
      8:
        EXIT(RFStatEntryTotal2."ATO Quantity" <> 0);
      10:
        EXIT( 
          (RFStatEntryTotal2."Outstanding No. of Lines" = 1)
        AND 
          (RFStatEntryTotal2."Outstanding Quantity" <> 0)
        );
      11:
        EXIT(
          (RFStatEntryTotal2."Outstanding No. of Lines" = 1)
        AND 
          (RFStatEntryTotal2."Available Quantity" <> 0)
        );
      12:
        EXIT(
          (RFStatEntryTotal2."Outstanding No. of Lines" = 1) 
        AND
          (RFStatEntryTotal2."Total Available Quantity" <> 0)
        );
      13:
        EXIT(
          (RFStatEntryTotal2."Outstanding No. of Lines" = 1) 
        AND 
          (RFStatEntryTotal2."Outstanding Quantity" = RFStatEntryTotal2."Available Quantity")
        );
      14:
        EXIT(
          (RFStatEntryTotal2."Outstanding No. of Lines" = 1) 
        AND 
          (RFStatEntryTotal2."Total Available Quantity" > RFStatEntryTotal2."Available Quantity")
        );
      15:
        EXIT(
          (RFStatEntryTotal2."Outstanding No. of Lines" = 1) 
        AND 
          (RFStatEntryTotal2."Inv. Reserved Quantity" <> 0)
        );
      16:
        EXIT(
          (RFStatEntryTotal2."Outstanding No. of Lines" = 1) 
        AND 
          (RFStatEntryTotal2."Outstanding Quantity" <> 0) 
        AND 
          (RFStatEntryTotal2.Quantity = RFStatEntryTotal2."Outstanding Quantity")
        );
      17:
        EXIT(
          (RFStatEntryTotal2."Outstanding No. of Lines" = 1) 
        AND 
          (RFStatEntryTotal2."Outstanding Quantity" <> 0) 
        AND 
          (WarehouseRequestTmp."Shipment Date" < WORKDATE)
        );
      18:
        EXIT(
          (RFStatEntryTotal2."Outstanding No. of Lines" = 1) 
        AND 
          (RFStatEntryTotal2."ATO Quantity" <> 0)
        );
    END;
    
    LOCAL IsBetweenMinMax(CheckValue : Decimal;MinimumValue : Decimal;MaximumValue : Decimal) : Boolean
    EXIT(
      (CheckValue >= MinimumValue)
    AND (
        (CheckValue <= MaximumValue) 
      OR
        (MaximumValue = 0)
    ));
    
  • Options
    ara3nara3n Member Posts: 9,255
    Thanks. I posted this as an example of how not to code. And this part of Eship Lanham ACE warehousing solution code.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.