0

button to make an record in the table

There's a quick entry page.
It has a dynamic selection field Project3
It has a dynamic selection field expenses
a number  field amount
a text field comment
a image field Image
I need a formula for digging to select the desired project in the table project1 which contains a subtable expenses and makes a record there in the fields with the same names.

Reference field project2

let thisRec := this;
let projRec := first(select Project1 where Project = thisRec.Project3);
if projRec != null then
    (create 'Expanses name').(
        Project2 := projRec;
        Expenses := thisRec.Expenses;
        Amount := thisRec.Amount;
        Comment := thisRec.Comment;
        Image := thisRec.Image
    );
    alert("Expense record created.")
else
    alert("Project not found.")
end

 

 alert "Expense record created."

thanks

4 replies

null
    • Fred
    • 3 days ago
    • Reported - view

    You will need two create() commands. Something like:

    let thisRec := this;
    let projRec := record(Project1,number(Project3));
    if projRec != null then
        let newProj := (create Project1);
        (create 'Expanses name').(
            Project2 := newProj;
            Expenses := thisRec.Expenses;
            Amount := thisRec.Amount;
            Comment := thisRec.Comment;
            Image := thisRec.Image
        );
        alert("Expense record created.")
    else
        alert("Project not found.")
    end
    
      • iliper LTD
      • iliper_LTD
      • 2 days ago
      • Reported - view

       Good morning
      Your PDF formula creates a record in the projects table. But it creates a new record, not a record for the specified project field project3

    • Fred
    • 2 days ago
    • Reported - view

    oops, sorry for mis-reading the issue. Try:

    let thisRec := this;
    let projRec := record(Project1,number(Project3));
    if projRec != null then
        var share := shareFile(thisRec.Image);
        var fileName := extractx(text(thisRec.Image), "\/(.*)", "$1");
        let newExpense := (create 'Expanses name');
        newExpense.(
            Project2 := projRec;
            Expenses := thisRec.Expenses;
            Amount := thisRec.Amount;
            Comment := thisRec.Comment;
            Image := importFile(newExpense, share, fileName);
            unshareFile(Image)
        );
        alert("Expense record created.")
    else
        alert("Project not found.")
    end
    

    Lines 4,5,12,& 13 are new because to copy an image file between records goes through a different method. Also it only works in the Cloud version as it uses the shareFile() command.

    If you are using dynamic fields then you should get comfortable using the record() command as it is a faster way of getting the selected record.

      • iliper LTD
      • iliper_LTD
      • 2 days ago
      • Reported - view

      Thank You

Content aside

  • Status Answered
  • 2 days agoLast active
  • 4Replies
  • 29Views
  • 2 Following