SETRANGE Issue not showing data for multiple value

mdsrmdsr Member Posts: 163
Hi all,

i want add restriction on posting of item journal as per location for that i have done following implementation:

usersetup table:91 created field :loc. area code 200 run table adding value to this field as red|blue|green

on item jounal onaction of post addid code as:

UserSetup.RESET;
UserSetup.SETRANGE("Loc area",Rec."Location Code");
IF UserSetup.FIND('-') THEN
BEGIN
CODEUNIT.RUN(CODEUNIT::"Item Jnl.-Post",Rec);
CurrentJnlBatchName := GETRANGEMAX("Journal Batch Name");
CurrPage.UPDATE(FALSE);
END
ELSE
MESSAGE('USER NOT VALID FOR THIS LOCATION: %1',"Location Code");

now it not allowing to post user with location code as blue,and red on item journal it giviong me error message why so.

Answers

  • AlexDenAlexDen Member Posts: 86
    Hi,

    Because you try to find equal value RED in user setup, but you have RED|BLUE|GREEN there.
    You have to use something like that:
    UserSetup.GET(USERID);
    
    Location.GET(Rec."Location Code");
    Location.SETRECFILTER;
    
    Location.FILTERGROUP(2);
    Location.SETFILTER(Code, UserSetup."Loc Area");
    Location.FILTERGROUP(0);
    
    IF NOT Location.FINDFIRST THEN
      MESSAGE('USER %1 NOT VALID FOR LOCATION %2', USERID, "Location Code");
    
  • mdsrmdsr Member Posts: 163
    edited 2019-09-23
    @AlexDen thanks it working partially it allow to post user from locationRED|BlUE|GREEN but problem is it allow posting when location code is yellow which is not in user setup loc area field. why?
    UserSetup.GET(USERID);
    
    Location.GET(Rec."Location Code");
    Location.SETRECFILTER;
    
    Location.FILTERGROUP(2);
    Location.SETFILTER(Code, UserSetup."Loc area");
    Location.FILTERGROUP(0);
    
    IF NOT Location.FINDFIRST THEN
      MESSAGE('USER %1 NOT VALID FOR LOCATION %2', USERID, "Location Code");
      IF NOT Location.FINDFIRST THEN
      CODEUNIT.RUN(CODEUNIT::"Item Jnl.-Post",Rec);
      CurrentJnlBatchName := GETRANGEMAX("Journal Batch Name");
      CurrPage.UPDATE(FALSE);
    
  • AlexDenAlexDen Member Posts: 86
    Try this
    UserSetup.GET(USERID);
    
    Location.GET(Rec."Location Code");
    Location.SETRECFILTER;
    
    Location.FILTERGROUP(2);
    Location.SETFILTER(Code, UserSetup."Loc area");
    Location.FILTERGROUP(0);
    
    IF NOT Location.FINDFIRST THEN
      ERROR('USER %1 NOT VALID FOR LOCATION %2', USERID, "Location Code")
    ELSE BEGIN 
      CODEUNIT.RUN(CODEUNIT::"Item Jnl.-Post",Rec);
      CurrentJnlBatchName := GETRANGEMAX("Journal Batch Name");
      CurrPage.UPDATE(FALSE);
    END;
    
  • mdsrmdsr Member Posts: 163
    @AlexDen thanks :) that's working....
    if possible can you please explain what exactly happening in code i have not get it what code is trying to say.
Sign In or Register to comment.