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

«1

Answers

  • tomarsuniltomarsunil Member Posts: 25
    Hey
    Why don't you Responsibility Center for this.
    if you user Responsibility Center it will help you out from this issue.
  • asinasin Member Posts: 25
    @KTA8 USER WILL HAVE BOTH FROM AND TO...
  • asinasin Member Posts: 25
    @tomarsunil responsibility center is there only for sales ans purchase not for transfer orders na?
  • KTA8KTA8 Member Posts: 397
    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 Member Posts: 25
    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 Member Posts: 228
    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.
  • asinasin Member Posts: 25
    @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 Member Posts: 228
    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);
    
  • asinasin Member Posts: 25
    @ShaiHulud thanks for ur immense support,actually much in trouble with this part....very much worried with...
    my client comp dont want from-to date restriction so i went with user and location restriction only.
    I have specified all as you said....

    still getting the error shown in attached screenshot.
    user :=(current logged in user) and Transfer-to Code := (is the location code the user entered)
    i am trying to call the function so that it can check if current user and given location is defined in in mylocation table or not if not it will show error msg(example if india japa and france are 3 locations,and user is James.if in mylocation table James is assigned with only india and japan) so if James enters france at transfer-to code then he will get the error msg.

    I am also attache the transfer header table in txt format and mylocations table also in txt format.


    plz plz help
  • ShaiHuludShaiHulud Member Posts: 228
    @asin You forgot to include the attachments :)
  • asinasin Member Posts: 25
    oh oh ohhh sorry sorry will attach 2mrw mrning.....sorry :(
  • asinasin Member Posts: 25
    @ShaiHulud txt format for the table is not allowed
    wd u plz share ur mail id...my one anosua@outlook.com
  • ShaiHuludShaiHulud Member Posts: 228
    @asin Your problem is that you haven't defined the parameters fro CheckLocationUser function. You try to call that function with 2 parameters, but the function definition does not have any parameters, so you get an error.
    Go to the function CheckLocationUser and open its local variables (CTRL+L on NAV 2016+). Then under parameters tab define MyUserID (code [50]) and MyLocationCode (code [20]).
    It should look something like this:
    cn6ga9wf2g62.png
    And then make sure MyUserID and MyLocationCode do NOT exist as global variables as well, because then it will NOT work.
  • asinasin Member Posts: 25
    @ShaiHulud this is how i mentioned the variables....it would be better if i can send you the .fob or .txt ...but here is no scope
  • ShaiHuludShaiHulud Member Posts: 228
    @asin your last screenshot ("local variable under the function.jpg") is where you made the mistake - you need to move those variables from the tab "variables" to "parameters". See the screenshot I added on my previous post.
  • asinasin Member Posts: 25
    @ShaiHulud ok ..thanks...corrected the mistake...till getting the errorrqad5azu8s8d.jpg
  • ShaiHuludShaiHulud Member Posts: 228
    You haven't set a return value value on function CheckLocationUser. Open up local variables of that function, navigate to "Return Value" tab and set "Return Type" to "boolean"
  • asinasin Member Posts: 25
    @ShaiHulud still getting error .have assigned user with a location but if the user inputs the assigned location gets error.
  • ShaiHuludShaiHulud Member Posts: 228
    In all the screenshots you never actually posted what your CheckLocationUser function code looks like now. Could you do that?
  • asinasin Member Posts: 25
    @ShaiHulud ya sure....i am at home right now will send you tomorrow morning....i will do definitely.....btw...i know i am repeating...still the amount i am knocking you really i should thanks you so many times...
  • asinasin Member Posts: 25
    edited 2019-08-28
    @ShaiHulud As I have created Mylocations table to assign locations against user id,I found that it is not allowing to specify the same user with another location ,so I am not being able to enter multiple location for a certain user.
    Another table for example,warehouse employee does the same,sending you the screenshots....but instead of using Mylocations table,i can also use the warehouse employee table bit the problem is that it has common names of variable like user,location.....it may clash as you said earlier?

    ql89y9lzm8ra.jpg

    but warehouse employee table with similar
    fields allowing to assign multiple locations as shown below

    3397fyhea6z5.jpg


  • ShaiHuludShaiHulud Member Posts: 228
    OK, first thing's first, your CheckLocationUser function is written incorrectly. If you look at my first post, you will notice that I suggest you EXIT with the value of MyLocations.FINDFIRST, meaning, if we find an entry, we EXIT with TRUE, if not, then we EXIT with FALSE.
    Your code just exits. The last two lines of the function code need to be replaced with:
    EXIT(MyLocations.FINDFIRST)
    
    That will make that part work

    The other thing, why you're not able to insert more records is because your primary key (the fields defining each record as unique) only consists of field "User ID". This means that when you try to insert another location for the user, NAV checks and sees that there is already a record in the table with the same unique "identifier", because Location Code is NOT part of the primary key ("identifier").
    To add Location Code to the Primary Key, you should first delete all the records from the table, then go back to the designer, design the table, then click on the View->Keys. This will open a window with all the keys defined on the table. The first key in the list is ALWAYS the primary key
    qsjtzhpvch5x.png
    Please read up on the keys, what they do, how to define and use them. You need to add field "Location Code" to the first (primary) key.

    And finally, as you've noticed yourself, there's already a Warehouse Employee table. If none of the other functions/modules you use makes use of that table, you can use it for your own needs. In your code you then need to replace the MyLocations table with Warehouse Employee table (change variable name, subtype and then rename it in the code as well).

    If you do decide to go with this, your final CheckLocationUser code should look like:
    LOCAL CheckLocationCode (MyUserID : Code [50], MyLocationCode : Code [20]) : Boolean
    EXIT(WarehouseEmployee.GET(MyUserID, MyLocationCode));
    
    Here WarehouseEmployee is a record type variable with subtype "Warehouse Employee". See my first post on using GET instead of filtering first.
  • asinasin Member Posts: 25
    @ShaiHulud sorry for being late to reply, as I have joined today office after wrestling with fever:)...Today I applied as per your mail the function is running perfectly, i am trying to dvelope few added things on that....

    1)If location left blank against any user in mylocations table then, the user can have access to any location.like if left blank then skips the error message and can enter any location he want to

    2)In transfer order form,if user A is given access to 11 and 22 location ,then he can only ship to 11 and 22 location,cannot ship and receive both to 11 and 22 location

    3)the above mentioned thing ,i suppose can be done by specifying the same function calling in Transfer order post receipt codeunit (under Onrun).So that if i assign recieving locationg same as transfer location for any user then he can only recieve for those location,else will get error.
    if he tries to recieve the order then the function will check if transfer to code and reciving location code is same or not if not then will show the error message.

    is it ok?
  • ShaiHuludShaiHulud Member Posts: 228
    1. You should rewrite your CheckLocationCode function to be like this then:
    LOCAL CheckLocationCode (MyUserID : Code [50], MyLocationCode : Code [20]) : Boolean
    WarehouseEmployee.SETRANGE("User ID", MyUserID);
    WarehouseEmployee.SETFILTER("Location Code", '%1|%2', MyLocationCode, ''); //this will look for location codes either fitting the one you specify, or blank code
    EXIT(WarehouseEmployee.FINDFIRST);
    
    2. You cannot transfer to the same location as the source (from- and to- cannot be the same), so you don't need to check for that at all. Not sure I understand I understand the problem
    x3imfalqd4pc.png
  • asinasin Member Posts: 25
    @ShaiHulud the thing is running but I hv done the second and last (apparently, as my CEO said) modification on this form is that...In Mylocations table i have created one more column as "Receiving Location".Now admin will assign same way as he done for transfer to location.
    Suppose the user 0027 is assigned with location "SUPREME". then suppose the user tries to receive a transfer order that has transfer to location "PROD" then he get the error(same error as we done before...you r not assigned etc."
    if "transfer to location" <>"receiving location" then user will get error after clicking "OK" of "receive" Boolean
    if transfer to location and receiving location(assigned to user in the table) is same then he will not get error.
    for that should i copy the same code on transfer order post reciept table or anything alse?plz advice
    thanks a lot
    66.jpg 74.2K
    55.jpg 164.7K
  • ShaiHuludShaiHulud Member Posts: 228
    You need to make the check on validation of "Transfer-to Code", because doing it on "Receive" posting action will be way too late - it will already be shipped to the new location, because "Ship" is the first step and disables editing of most of the order.
    CheckReceivingLocation(MyUserID : Code [50], MyFromLocationCode : Code [20], MyToLocationCode : Code [20]) : Boolean
    WarehouseEmployee.SETRANGE("User ID", MyUserID);
    WarehouseEmployee.SETFILTER("Location Code", '%1|%2', MyFromLocationCode, '');
    WarehouseEmployee.SETFILTER("Receiving Location", '%1|%2', MyToLocationCode, '');
    EXIT(WarehouseEmployee.FINDFIRST);
    
  • asinasin Member Posts: 25
    @ShaiHulud ,Suppose there is a user “John”,who has only assigner with transfer from location and he is let assume assigned with location “main Store”…i.e., he can only ship anything from “mainstore” location to any location….he do so. But after that he went to the transfer line and now he clicks the post button and receives the items….as has no checking for user-id and receiving location .

    So the user can receive any released transfer order on behalf of the to location code .
    If I put the function calling in transfer to location then the user cannot ship to that location which he is not assigned to. But which is required that he can ship to any location but cannot receive the shipped order .That’s why I want to put the code when post receiveok is clicked.
    77.jpg 262.7K
    55.jpg 164.7K
  • asinasin Member Posts: 25
    @ShaiHulud i.e. user can ship means enter any location in the field transfer to code but only can receive orders for which "transfer to location" = "receiving location"(assigned through mylocations table) for the user
Sign In or Register to comment.