Setting boolean flag on a table

havhav Member Posts: 299
Hi,
I am using NAV 2009 NA-ENG SP1.
I have added a boolean var. IsWMItemDeletionReqd and a function SetIsWMItemDeletionReqd() to SalesLine table as below.
SetIsWMItemDeletionReqd(flag : Boolean)
BEGIN
    IsWMItemDeletionReqd := flag;  //IsWMItemDeletionReqd is a global boolean var.
END

I am calling the above function from the OnDeleteRecord() trigger of Sales Order Subform as below
Form - OnDeleteRecord() : Boolean
IF (Quantity <> 0) AND ItemExists("No.") THEN BEGIN
  COMMIT;
  IF NOT ReserveSalesLine.DeleteLineConfirm(Rec) THEN
    EXIT(FALSE);
  ReserveSalesLine.DeleteLine(Rec);
END;

// Execute WMERP code only if WM add-on is enabled
IF NOT WMI.IsWMAddOnDisabled() THEN BEGIN
  // Restrict deletion of G/L Account type of WM Sales Lines directly
  IF (Type = Type::"G/L Account") AND (WMItemNo <> '') THEN BEGIN
    MESSAGE(TEXT002);
    EXIT(FALSE);
  END ELSE BEGIN
    // Set flag to mark deletion of WM Item along with current salesline
    SetIsWMItemDeletionReqd(TRUE);
    EXIT(TRUE);
  END;
END;

And the OnDelete() trigger of Sales Line table is as below
OnDelete()
BEGIN
  ...............
  IF IsWMItemDeletionReqd THEN BEGIN
    // Delete WM Item corr. to Sales Line of type Item only. 
    IF (Rec.WMItemNo <> '') AND (Rec.Type = Rec.Type::Item) THEN
      WMI.DeleteItem(SalesHeader, Rec);  //WMI is a codeunit
  END;
END;

The objective is that when user deletes a sales line from either the Sales Quote or Sales Order form, the program first calls OnDeleteRecord() of the underlying subform wherein i first set the flag IsWMItemDeletionReqd to true in SalesLine table so that when later OnDelete() trigger of the underlying table is called, the function WMI.DeleteItem() should get called.
However the problem is inspite of setting the flag from the subform when i later access it in the salesline table, the flag is not seen as True and hence my function is not getting called.

Am i missing something?

Regards,
Hemant
Regards,
Hemant
MCTS (MB7-841 : NAV 2009 C/SIDE Solution Development)

Answers

  • kapamaroukapamarou Member Posts: 1,152
  • havhav Member Posts: 299
    Thanks for your response.
    I have now worked out in below manner:
    Added IsWMItemDeletionReqd global var. to WMI codeunit instead of SalesLine table
    Moved the SetIsWMItemDeletionReqd() function from SalesLine table to WMI codeunit.
    So now from the OnDeleteRecord() trigger of the Quote & Order subform, i make a call as
    Form - OnDeleteRecord() : Boolean
    BEGIN
        ..........
        WMI.SetIsWMItemDeletionReqd(TRUE);
    END;
    
    and from the OnDelete() trigger of Salesline table,
    OnDelete()
    BEGIN
      ...............  
        // Delete WM Item corr. to Sales Line of type Item only. 
        IF (Rec.WMItemNo <> '') AND (Rec.Type = Rec.Type::Item) THEN
          WMI.DeleteItem(SalesHeader, Rec);  //WMI is a codeunit
        WMI.SetIsWMItemDeletionReqd(FALSE);
      END;
    END;
    
    and from the DeleteItem() of the WMI codeunit,
    DeleteItem(VAR SalesHeader : Record "Sales Header";VAR SalesLine : Record "Sales Line")
    BEGIN
      //Restrict deletion to WM Item if only sales line is to be deleted
      IF NOT IsWMItemDeletionReqd THEN EXIT;
      ..........
    END; 
    

    The above works fine.

    Regards,
    Hemant
    Regards,
    Hemant
    MCTS (MB7-841 : NAV 2009 C/SIDE Solution Development)
Sign In or Register to comment.