transfer to and from location restriction

I want to restrict transfer To and From location as details mentioned below
Have a glimpse of the form given below I have 100 locations. now when initiating a transfer order I want to give permission to users so that user can enter only one permitted location at transfer from location...(may be through security filter)

Now I have created another table where I can specify locations against each user. So that at Transfer To location user can only enter the locations that are specified onto the table against their user id

like if my login user id is "production" ,then I can only enter transfer to locations among that are specified on that table, against the Production User id



seze2v0g0sbo.jpg
u9as9l8rx0tz.jpg


I can pick up current user id but compairing the user id with the said table and pick locations that are fixed against the user id ....i cant manage the coding....plz help me out

Best Answer

Answers

  • tomarsuniltomarsunil indiaPosts: 22Member
    Hey
    Why don't you Responsibility Center for this.
    if you user Responsibility Center it will help you out from this issue.
  • asinasin Posts: 8Member
    @KTA8 USER WILL HAVE BOTH FROM AND TO...
  • asinasin Posts: 8Member
    @tomarsunil responsibility center is there only for sales ans purchase not for transfer orders na?
  • KTA8KTA8 Posts: 275Member
    asin wrote: »
    @KTA8 USER WILL HAVE BOTH FROM AND TO...

    Isn't I was asking, but you can have for one user various records.

    You can do something like this

    Function CheckLocationUser(User, Location)

    MyLocations.RESET;
    MyLocations.SETRANGE(User ID,User);
    MyLocations.SETRANGE(Location Code,Location);
    IF (MyLocations.FINDFIRST()) THEN
    EXIT(TRUE)
    ELSE
    EXIT(FALSE)

    Then on the transfer from and to validate.

    IF NOT (CheckLocationUser(USERID, Transfer-from Code)) THEN
    ERROR('Your mesage');

  • asinasin Posts: 8Member
    edited 2019-08-13
    @KTA8
    I have created a table named MyLocation, consists two fields location and user id as follows
    c1ew2sksnm6u.jpg

    Now as per your solution I have implemented the code but getting errors regarding defining variables …
    I have defined user id and location variable under the function checkloacion

    and defined global variables myLocation=record--tablename
    user--recrd-user
    location--record -location

    Have defined the function as well still error..
    w94h2qgvu97w.jpg

    fmxur8bp1pbj.jpg


    is there something I miss during declaration of variables

  • ShaiHuludShaiHulud Posts: 45Member
    Your CheckLocationUser function does not have any parameters declared, yet in "Transfer-to Code" OnValidate, you call it with 2 parameters.
    You need to add 2 parameters to CheckLocationUser: "User" (type code[50]) and "Location" (type code [10]), although personally, I'd use different names, because "User" and "Location" are table names as well, so it might be confusing later on.
    Arturas Kulsinskas
    NaviLogic
  • asinasin Posts: 8Member
    @ShaiHulud .. ok so under checklocation function I should define these two variables with slight different names like myuser and myloc... with type code


    my requirement is there is a table consists user ids and location(as you saw in screenshot) then when I login and try to enter a location code in transfer to location then system will check if current user id is assigned with that location in that table if the location is not defined for the user then it will show error message else will permit...

    is it serve the requirement?

  • ShaiHuludShaiHulud Posts: 45Member
    asin wrote: »
    @ShaiHulud .. ok so under checklocation function I should define these two variables with slight different names like myuser and myloc... with type code


    my requirement is there is a table consists user ids and location(as you saw in screenshot) then when I login and try to enter a location code in transfer to location then system will check if current user id is assigned with that location in that table if the location is not defined for the user then it will show error message else will permit...

    is it serve the requirement?

    Yes, that will do what you want. Although you can simplify your code in CheckLocationUser function:
    LOCAL CheckLocationUser (MyUserID : Code [50], MyLocationCode : Code [20])
    MyLocations.SETRANGE("User ID", MyUserID);
    MyLocations.SETRANGE("Location Code", MyLocationCode);
    EXIT(MyLocations.FINDFIRST);
    
    You don't need RESET if "MyLocations" is declared as local variable, because it gets cleared automatically as soon as the function finishes executing
    FINDFIRST has a return value (TRUE if found, FALSE if not), so we can just put that into EXIT.
    Alternatively, if your MyLocations table's Primary Key consists only of "User ID" and "Location Code", your entire function code can be simply:
    LOCAL CheckLocationUser (MyUserID : Code [50], MyLocationCode : Code [20])
    EXIT(MyLocations.GET(MyUserID, MyLocationCode); //assuming that's the Primary Key field order
    

    If I understand correctly, you also have a date filter (from when to when the user can use a specific location). If so, then you need to use the first example, and add additional filters as well as a new parameter (must not forget it when calling the function! I suggest using "Posting Date" or "Document Date", depending on your needs):
    LOCAL CheckLocationUser (MyUserID : Code [50], MyLocationCode : Code [20], PostingDate : Date)
    MyLocations.SETRANGE("User ID", MyUserID);
    MyLocations.SETRANGE("Location Code", MyLocationCode);
    MyLocations.SETRANGE("Date From", 0D, PostingDate); //looking for locations with "Date From" between beginning of time until the Transfer Order Posting Date (or another Date you pass to this function)
    MyLocations.SETFILTER("Date To", '%1..|%2', PostingDate,0D); //looking for locations with "Date To" between the Transfer Order Posting Date (or another Date you pass to this function) or no date (in case it was left blank)
    EXIT(MyLocations.FINDFIRST);
    
    Arturas Kulsinskas
    NaviLogic
Sign In or Register to comment.