0

Button for writing to another table

Hello

There is a button, in the sub table Cash Desk.Expenses, that should make a record in another table. 

to Table ADVANSE

formula for button is

let x := dialog("NEW RECORD", "CREATE NEW RECORD?", ["No", "Yes"]);
if x = "Yes" then
    let d := Date;
    let xCurrRec := Id;
    let xNewName := Name;
    let xNewAmounnt := Amount;
    let xNewComment := Comment;
    let i := (create ADVANSE);
    i.(EMPLOYEES := xNewEmploee);
    i.(Name := xNewName);
    i.(Amount := xNewAmounnt);
    i.(COMMENT := xNewComment)
end 

as you can see in the second picture, this is a table of employees, and I need it when I make a record using the button, it is written into the personal table of each employee. There is a link to the table Expenses Tab to Employees N:1

Help edit the formula.

Thank you all

5 replies

null
    • Fred
    • 3 mths ago
    • Reported - view
    let x := dialog("NEW RECORD", "CREATE NEW RECORD?", ["No", "Yes"]);
    if x = "Yes" then
        let d := Date;
        let xCurrRec := Id;
        let xNewName := Name;
        let xNewAmounnt := Amount;
        let xNewComment := Comment;
        let i := (create ADVANSE);
        i.(EMPLOYEES := xNewEmploee);
        i.(Name := xNewName);
        i.(Amount := xNewAmounnt);
        i.(COMMENT := xNewComment)
    end 

    Just a tip, since you put the current record Id into a variable, line 4, you can just use that to reference all your fields. So it would look like:

    let x := dialog("NEW RECORD", "CREATE NEW RECORD?", ["No", "Yes"]);
    if x = "Yes" then
        let d := Date;
        let xCurrRec := Id;
        let i := (create ADVANSE);
        i.(
    EMPLOYEES := xCurrRec.EMPLOYEES;
         Name := xCurrRec.Name;
         Amount := xCurrRec.Amount;
         COMMENT := xCurrRec.Comment
    )
    end 

    This should also link the new record in ADVANSE to the proper EMPLOYEE record.

      • iliper LTD
      • iliper_LTD
      • 3 mths ago
      • Reported - view

       Good evening

      In both cases I get an error

      in the first there were two and I corrected it, but the result is the same

      this is what the page looks like where there is a button, all the other 4 fields are identical to those where the record goes

      • Fred
      • 3 mths ago
      • Reported - view

      1) the variable i is the new record in the ADVANCE table so that is where it is looking and it looks like there is no field called EMPLOYEES.

      2) you use a variable xNewEmploee but do not define it.

      • iliper LTD
      • iliper_LTD
      • 3 mths ago
      • Reported - view

       Morning

      I created a text field "employees", there is no error anymore. What is interesting is that the record is displayed in the "advance" table itself, but it is not in the sub-table that is in the employee account. Records are not linked to an employee

      in another table, the button with the same function makes a record in another table, and there the record is linked to a specific user, client. It looks like this

      
      let xCurrRec := this;
      let DRselect := (select 'Daily Result')['List of Players' = xCurrRec.CUSTOMER and Date = xCurrRec.Date];
      let DRcheck := count(DRselect);
      let x := dialog("CASH IN", "add new record?", ["No", "Yes"]);
      if x = "Yes" then
      switch DRcheck do
      case 0:
      (
       let newDR := (create 'Daily Result');
       newDR.(
       'List of Players' := xCurrRec.CUSTOMER;
      Date := xCurrRec.Date
      );            let i := (create 'Cash In/Out');
      
      i.(                Result := newDR;
                         Date := xCurrRec.Date;
                         Customer := xCurrRec.CUSTOMER;
                         'Casino Cash +' := xCurrRec.'.CASH.';
                         'Casino USD +' := xCurrRec.'.USD.';
                         'Casino EU +' := xCurrRec.'.EU.';
                         'Casino POU +' := xCurrRec.'.POU.';
                         'Casino VISA +' := xCurrRec.'.VISA/MC.'
      )
      )
      default:
      (
                         let newDR := first(DRselect);
                         let i := (create 'Cash In/Out');
                         i.(
                         Result := newDR;
                      Date := xCurrRec.Date;
                      Customer := xCurrRec.CUSTOMER;
                      'Casino Cash +' := xCurrRec.'.CASH.';
                      'Casino USD +' := xCurrRec.'.USD.';
                      'Casino EU +' := xCurrRec.'.EU.';
                      'Casino POU +' := xCurrRec.'.POU.';
                      'Casino VISA +' := xCurrRec.'.VISA/MC.';
      )
      )
      end
    • Fred
    • 3 mths ago
    • Reported - view
     said:
    What is interesting is that the record is displayed in the "advance" table itself, but it is not in the sub-table that is in the employee account. Records are not linked to an employee

    I don't know how your DB is built so I can't help you with specific field names.

    What is the name of the reference field in ADVANCE to EMPLOYEES? Use that in your code.

Content aside

  • 3 mths agoLast active
  • 5Replies
  • 52Views
  • 2 Following