0

How can I reference the present record/table in a select statement?

I want to use this select statement in a trigger after update in my Projects table:

select Invoices where SameAsProject = true and Client = Client

I want the first Client to reference Client in Invoices (Invoices.Client)

I want the secound Client to reference the Client of the present record (Projects.Client)

8 replies

null
    • Manne_Kjellander
    • 4 yrs ago
    • Reported - view

    I want to do something like:

     

    let C := Client;
    for I in select Invoices where SameAsProject = true and Client = C do
    I.(Client := C)
    end

    ..to update all Invoices that has SameAsProject=true when I update the Project Client.

    • Sean
    • 4 yrs ago
    • Reported - view

    Try this...

     

    let C := this.Client

    • Manne_Kjellander
    • 4 yrs ago
    • Reported - view

    Ok now I have this but it's still not working.

    for I in select Invoices where SameAsProject = true and Client = this.Client do
    I.(Client := this.Client)
    end

    • Manne_Kjellander
    • 4 yrs ago
    • Reported - view

    Looks like its giving the right selection for I, but it doesn't change the value in I.Client...

    for I in select Invoices where SameAsProject = true and Client = this.Client do
    I.(Client := this.Client);
    alert(text(I.Id))
    end

    • Sean
    • 4 yrs ago
    • Reported - view

    You had...

     

    let C := Client;

     

    I'm saying this...

     

    let C := this.Client;

     

    so it would be...

     

    let C := this.Client;
    for I in select Invoices where SameAsProject = true and Client = C do
    I.(Client := C)
    end

    • Sean
    • 4 yrs ago
    • Reported - view

    When you say you want to update all the Invoices, do mean you want to link the records?

    • Manne_Kjellander
    • 4 yrs ago
    • Reported - view

    Yes, I put this.Client inside the select statement instead of using a variable. Should be the same, right?

    For all records in the selection, I want to change the link in Client to whatever client this.Client is pointing at..

    • Sean
    • 4 yrs ago
    • Reported - view

    If I recall correctly, I tried to use "this" directly in a formula in the past and it didn't work so I got in the habit of assigning it to a variable. They make changes when they update the app, but don't completely update the documentation. Formerly you needed to use option+return to insert a New Line in a formula, now you can just use return.

     

    Try this to link records to the current record...

     

    let thisId := Id;
    let thisClient := Client;
    for i in select Invoices where SameAsProject = true and Client = thisClient do
    i.(Projects := thisId)
    end

Content aside

  • 4 yrs agoLast active
  • 8Replies
  • 1785Views