[Solved] Create permission for running report

andri0111andri0111 Posts: 5Member
edited 2019-02-08 in NAV Three Tier
Hi,

I try to create permission for running report, first I create new table

User Name | Report ID | Location ID
UserTest | 50000 | Store02
UserTest | 50000 | Store03
UserTest | 50000 | Store04

I already try, if UserTest running Report 50000 with filter Item.Store Filter 'Store02|Store03' it's ok
the problem is when I try filter 'Store02|Store04'
OnInit
EVALUATE(varReportID,COPYSTR(CurrReport.OBJECTID(FALSE),8,STRLEN(CurrReport.OBJECTID(FALSE)) - 7)); // get ID report

recRtlUsrStpRprt.SETRANGE("User Name",USERID);
recRtlUsrStpRprt.SETRANGE("Report ID",varReportID);
IF recRtlUsrStpRprt.FINDSET THEN BEGIN  
  varFilter := '';
  REPEAT
    IF varFilter = '' THEN
      varFilter := recRtlUsrStpRprt."Location ID"
    ELSE
      varFilter += '|' + recRtlUsrStpRprt."Location ID";
  UNTIL recRtlUsrStpRprt.NEXT = 0;
END ELSE 
  ERROR(Text01,USERID);

OnPreDataItem
IF STRPOS(varFilter,Item.GETFILTER("Store Filter")) = 0 THEN BEGIN
  ERROR(Text02,USERID);
  CurrReport.QUIT;
END;

Answers

  • krikikriki Posts: 8,768Member, Moderator
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • andri0111andri0111 Posts: 5Member
    Today I try use this, and solved the problem
    OnInitReport
    CheckPermissionReport(CurrReport.OBJECTID(FALSE),USERID,FALSE,'');
    
    OnPreDataItem
    CheckPermissionReport(CurrReport.OBJECTID(FALSE),USERID,TRUE,Item.GETFILTER("Store Filter"));
    
    Local CheckPermissionReport
    EVALUATE(lvarReportID,COPYSTR(pReportID,8,STRLEN(pReportID) - 7)); // get ID report
    
    IF pCheckStoreID THEN BEGIN // check Store Filter
      CLEAR(lrecRtlUsrStpRprt);
      lrecRtlUsrStpRprt.RESET;
      lrecRtlUsrStpRprt.SETRANGE("User Name",pUserID);
      lrecRtlUsrStpRprt.SETRANGE("Report ID",lvarReportID);
      lrecRtlUsrStpRprt.SETFILTER("Location ID",pStoreFilter);
      IF NOT lrecRtlUsrStpRprt.FINDSET THEN
        ERROR(Text02,pUserID);
    END ELSE BEGIN  // check Report ID
      CLEAR(lrecRtlUsrStpRprt);
      lrecRtlUsrStpRprt.RESET;
      lrecRtlUsrStpRprt.SETRANGE("User Name",pUserID);
      lrecRtlUsrStpRprt.SETRANGE("Report ID",lvarReportID);
      IF NOT lrecRtlUsrStpRprt.FINDFIRST THEN
        ERROR(Text01,pUserID);
    END;
    
  • andri0111andri0111 Posts: 5Member
    andri0111 wrote: »
    Today I try use this, and solved the problem
    OnInitReport
    CheckPermissionReport(CurrReport.OBJECTID(FALSE),USERID,FALSE,'');
    
    OnPreDataItem
    CheckPermissionReport(CurrReport.OBJECTID(FALSE),USERID,TRUE,Item.GETFILTER("Store Filter"));
    
    Local CheckPermissionReport
    EVALUATE(lvarReportID,COPYSTR(pReportID,8,STRLEN(pReportID) - 7)); // get ID report
    
    IF pCheckStoreID THEN BEGIN // check Store Filter
      CLEAR(lrecRtlUsrStpRprt);
      lrecRtlUsrStpRprt.RESET;
      lrecRtlUsrStpRprt.SETRANGE("User Name",pUserID);
      lrecRtlUsrStpRprt.SETRANGE("Report ID",lvarReportID);
      lrecRtlUsrStpRprt.SETFILTER("Location ID",pStoreFilter);
      IF NOT lrecRtlUsrStpRprt.FINDSET THEN
        ERROR(Text02,pUserID);
    END ELSE BEGIN  // check Report ID
      CLEAR(lrecRtlUsrStpRprt);
      lrecRtlUsrStpRprt.RESET;
      lrecRtlUsrStpRprt.SETRANGE("User Name",pUserID);
      lrecRtlUsrStpRprt.SETRANGE("Report ID",lvarReportID);
      IF NOT lrecRtlUsrStpRprt.FINDFIRST THEN
        ERROR(Text01,pUserID);
    END;
    

    update for CheckPermissionReport
    EVALUATE(lvarReportID,COPYSTR(pReportID,8,STRLEN(pReportID) - 7)); // get ID report
    
    IF pCheckStoreID THEN BEGIN // check Store Filter
      CLEAR(lrecStore);
      lrecStore.RESET;
      lrecStore.SETFILTER("No.",pStoreFilter);
      IF lrecStore.FINDSET THEN BEGIN
        lvarCheckStoreLoc := '';
        REPEAT
          CLEAR(lrecRtlUsrStpRprt);
          lrecRtlUsrStpRprt.RESET;
          lrecRtlUsrStpRprt.SETRANGE("User Name",pUserID);
          lrecRtlUsrStpRprt.SETRANGE("Report ID",lvarReportID);
          lrecRtlUsrStpRprt.SETRANGE("Location ID",lrecStore."No.");
          IF lrecRtlUsrStpRprt.FINDFIRST THEN
            lvarCheckStoreLoc += '1'
          ELSE
            lvarCheckStoreLoc += '0';
        UNTIL lrecStore.NEXT = 0;
      END;
      IF STRPOS(lvarCheckStoreLoc,'0') <> 0 THEN
        ERROR(Text02,pUserID);
    END ELSE BEGIN  // check Report ID
      CLEAR(lrecRtlUsrStpRprt);
      lrecRtlUsrStpRprt.RESET;
      lrecRtlUsrStpRprt.SETRANGE("User Name",pUserID);
      lrecRtlUsrStpRprt.SETRANGE("Report ID",lvarReportID);
      IF NOT lrecRtlUsrStpRprt.FINDFIRST THEN
        ERROR(Text01,pUserID);
    END;
    
Sign In or Register to comment.