×
Menu
Index

How to implement NavSherpa functions with Events

NavSherpa contains NavSherpa Interface (Codeunit 4065007), sometimes called the NavSherpa API. This NavSherpa module provides functions that can be used for managing data relations from code.
 
If NavSherpa functions are used in an object, add the NavSherpa version to the object's "Version List". Minimal text is NSPW110.00. This is necessary to identify the changes.
 

Example of how to use the functions from C/AL code

VAR
  NotApprovedErr@1003 : TextConst 'ENU=The result of workflow "%1"  must be ''%2''.';
  ApprovedCpt@1002 : TextConst 'ENU=Approved';
  ListType@4065000 : 'List,Library';
 
[EventSubscriber(Codeunit,90,OnBeforePostPurchaseDoc,"",Skip,Skip)]
LOCAL PROCEDURE OnBeforePostPurchaseDoc@2(VAR PurchaseHeader@1000 : Record 38);
VAR
  NavSherpaInterface@4065100 : Codeunit 4065007;
  NotApprovedWFName@4065103 : Text;
  EmptyRecordReference@4065000 : RecordRef;
BEGIN
  IF PurchaseHeader."Document Type" = PurchaseHeader."Document Type"::Invoice THEN BEGIN
    IF NOT NavSherpaInterface.IsAllWorkflowsApproved(PurchaseHeader,'',NotApprovedWFName) THEN
      ERROR(NotApprovedErr,NotApprovedWFName,ApprovedCpt);
    NavSherpaInterface.CheckCopyMapping(ListType::Library,PurchaseHeader,'','',EmptyRecordReference,'',DATABASE::"Purch. Inv. Header",'',FALSE);
  END;
END;
 
[EventSubscriber(Codeunit,90,OnAfterPostPurchaseDoc,"",Skip,Skip)]
LOCAL PROCEDURE OnAfterPostPurchaseDoc@4065000(VAR PurchaseHeader@4065000 : Record 38;VAR GenJnlPostLine@4065001 : Codeunit 12;PurchRcpHdrNo@4065002 : Code[20];RetShptHdrNo@4065003 : Code[20];PurchInvHdrNo@4065004 : Code[20];PurchCrMemoHdrNo@4065005 : Code[20]);
VAR
  NavSherpaInterface@4065100 : Codeunit 4065007;
  PurchInvHdr@4065101 : Record 122;
BEGIN
  IF PurchaseHeader."Document Type" = PurchaseHeader."Document Type"::Invoice THEN BEGIN
    IF PurchInvHdr.GET(PurchInvHdrNo) THEN BEGIN
      NavSherpaInterface.CopyDocumentMapping(PurchaseHeader,'','',PurchInvHdr,'','',FALSE);
      NavSherpaInterface.DeleteDocumentMapping(FALSE,PurchaseHeader,'');
    END;
  END;
END;
 
[EventSubscriber(Table,4,OnAfterDeleteEvent,"",Skip,Skip)]
LOCAL PROCEDURE OnAfterCurrencyDeleteEvent@4065001(VAR Rec@4065000 : Record 4;RunTrigger@4065001 : Boolean);
VAR
  NavSherpaInterface@4065100 : Codeunit 4065007;
BEGIN
  NavSherpaInterface.DeleteRecordMapping(Rec,'');
END;
 
[EventSubscriber(Table,38,OnAfterDeleteEvent,"",Skip,Skip)]
LOCAL PROCEDURE OnAfterPurchaseHeaderDeleteEvent@4065002(VAR Rec@4065000 : Record 38;RunTrigger@4065001 : Boolean);
VAR
  NavSherpaInterface@4065100 : Codeunit 4065007;
  PurchInvHeader@4065101 : Record 122;
BEGIN
  IF Rec."Document Type" = Rec."Document Type"::Invoice THEN BEGIN
    PurchInvHeader.SETRANGE("Pre-Assigned No.",Rec."No.");
    IF PurchInvHeader.ISEMPTY THEN BEGIN
      NavSherpaInterface.DeleteDocumentMapping(FALSE,Rec,'');
    END;
    NavSherpaInterface.DeleteRecordMapping(Rec,'');
    NavSherpaInterface.DeleteWorkflowMapping(Rec,'');
  END;
END;
 
[EventSubscriber(Table,13,OnAfterDeleteEvent,"",Skip,Skip)]
LOCAL PROCEDURE OnAfterSalespersonDeleteEvent@4065003(VAR Rec@4065000 : Record 13;RunTrigger@4065001 : Boolean);
VAR
  NavSherpaInterface@4065100 : Codeunit 4065007;
BEGIN
  NavSherpaInterface.DeleteRecordMapping(Rec,'');
  NavSherpaInterface.DeleteDocumentMapping(FALSE,Rec,'');
END;
 
[EventSubscriber(Table,23,OnAfterDeleteEvent,"",Skip,Skip)]
LOCAL PROCEDURE OnAfterVendorDeleteEvent@4065004(VAR Rec@4065000 : Record 23;RunTrigger@4065001 : Boolean);
VAR
  NavSherpaInterface@4065100 : Codeunit 4065007;
BEGIN
  NavSherpaInterface.DeleteRecordMapping(Rec,'');
  NavSherpaInterface.DeleteDocumentMapping(FALSE,Rec,'');
END;