Forum Discussion

ShihadShihad's avatar
ShihadShihad
Qrew Cadet
9 years ago

Auto population of data on form loading

Hi,

This is my situation, 
I have two tables employee_master and employee_job. In employee_master table, i have userid, empid,name,email.
In employee_job, i have userid,empid,designation,department etc. What i want is, when i load employee_job form, empid should be auto populated from employee_master based on userid(current user). Is there any way to do this without any trigger.

Thanks
  • Thete us a simple way and a more complicated way.

    The simple way,especially if there are no other relationships involving the Employee master table is to change the Key field of the employee master table to the userid.

    Note that you may want to Copy your app to try this first.

    Then, on your jobs table, you can have a formula field called [Current User] with a formula of User()

    Lastly a form rule that says

    When the field related armployee is blank change the related employee field to be the value in the field Current User.

    Note that the field that the form rule is acting on will be the field which is used in the relationship to the employer table.
    • ShihadShihad's avatar
      ShihadShihad
      Qrew Cadet
      Hi ..i am trying this solution. For that i created a current user formula field in employee job form. Then created a relationship between tables. But i couldnt create  the form rule properly. can u make it more clear?

      Or any other way without using relationship. or using javascript ?
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      I'm not sure how else to say the form rule

      Condition:
      When the field related armployee is blank

      Action:
      change the related employee field to be the value in the field Current User.
    • ShihadShihad's avatar
      ShihadShihad
      Qrew Cadet
      Thanks
      But the issue is, 
      i saved one record in employee job. Then, another user logged in ,that time the already saved record is showing in his name. 
  • MCFNeil's avatar
    MCFNeil
    Qrew Captain
    Yes,  The best way, which is also the easiest. is to slightly modify the button you are pushing from the master table.

    You probably have a button called "Add Employee Job"  you just need to insert one small line.

    Yours might look something like this:

    URLRoot() & "db/" & [_DBID_EMPLOYEE_JOBS] & "?a=API_GenAddRecordForm&_fid_12=" & URLEncode ([Record ID#])& "&z=" & Rurl()

    Just add another fid to be written to:
    You can copy the format of part of the code:  &_fid_12=" & URLEncode ([Record ID#])& "

    Change the fid from 12 to the field id that has your "empid" then if it is a user insert (User())
    Like this:

    &_fid_12=" & URLEncode (User())& "

    #NoCodeRequired
    • ShihadShihad's avatar
      ShihadShihad
      Qrew Cadet
      Hi
      i am not maintaining any 'add employee job' button. Independently, the form needs to be loaded with the data from master.
      Thanks