0

Copy text field to reference field

 

 

Hi Brain Trust,

Is this possible?

I would like to  trigger after update a text field (copy a text field) to a reference field. They are both in the same table.

The text field is populated from a Dynamic multiple choice field.

I would like to reference that choice.

Table1  has the following:

A text field named  Data1

A reference field  named DATA ITEMS

The text field in DATA ITEMS is named Data.

The reference fields DATA ITEMS and  the Dynamic multiple choice field  are pointed to the same table. Table2.

The Dynamic multiple choice field is located in another table. Table3

thanks for looking

18 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    Most things are possible.🙂

    Sam said:
    The reference fields DATA ITEMS and  the Dynamic multiple choice field  are pointed to the same table. Table2.
    The Dynamic multiple choice field is located in another table. Table3

    I'm a bit confused here. Do you have two dynamic Multi choice fields (dMC)? One in Table2 and one in Table3?

    To clarify: you want to copy data from Table1:Data1 to Data Items:Data when changes are made to Data1?

    And changes are made to Table1:Data1 from a dMC that is in Table1?

      • Sam.1
      • 1 yr ago
      • Reported - view

      Fred Hi Fred,

      yes—- To clarify: you want to copy data from Table1:Data1 to Data Items:Data when changesare made to Data1?

      One dMC. It is located in Table3

    • Sam.1
    • 1 yr ago
    • Reported - view

    The DATA ITEMS field is blank. The Data1 is populated. I would like them both to be populated when the trigger after update of Data1 is executed

    • Fred
    • 1 yr ago
    • Reported - view

    Since Table1 has the reference field to Table2 (called Data Items) that means there is a 1 to many relationship between the tables, 1 record in Table2 has many related records in Table1.

    Do you want the Data Items:Data to be updated with all of the data from Table1:Data1 as you add more records in Table1? Or do you want the last record in Table1 to have the final say in what is in Data Items:Data?

    How are Table1 and Table3 related? How does the dMC in Table3 update a record in Table1? Can you post the code in the Trigger for the dMC?

      • Sam.1
      • 1 yr ago
      • Reported - view

      Fred Table1 is a child of Table3

      dMC updates the text by the trigger I will send shortly

      • Sam.1
      • 1 yr ago
      • Reported - view

      Fred 

      if 'AUTO CREATE RECORDS' then

      do as server

      let xCurrRec := number(Id);

      let xTemplate := number('Other Data');

      for i in (select Table2)['Other Data' = xTemplate] do

      "CHECK TO SEE IF ITEM SHOULD BE CREATED";

      if contains(text('RECORDS TO BE CREATED'), i.Data) and not contains('RECORDS ALREADY CREATED', i.Data) then

      let j1 := (create Table1);

      j1.(Data := i.Data);

      j1.(Table3 := xCurrRec)

      end;

      "CHECK TO SEE IF ITEM SHOULD BE DELETED";

      if not contains(text('RECORDS TO BE CREATED'), i.Data) and contains('RECORDS ALREADY CREATED', i.Data) then

      delete (select Table1)[Table3 = xCurrRec and 'DATA ITEMS' = i.Data]

      end

      end

      end

      end

      • Sam.1
      • 1 yr ago
      • Reported - view

      Fred thanks again for looking!😊

    • Fred
    • 1 yr ago
    • Reported - view
    Sam said:
    let j1 := (create Table1);
    j1.(Data := i.Data);
    j1.(Table3 := xCurrRec)

     Question: is there a reason why you don't create the link to table2 when you create the records in the dMC trigger? You can add:

    let j1 := (create Table1);
    j1.(Data := i.Data;
    'Data Items' := i;
    Table3 := xCurrRec)
    

    Or is the link created in some other way?

      • Sam.1
      • 1 yr ago
      • Reported - view

      Fred Fred yes, a inventory/service item is added by choice in table1

      • Sam.1
      • 1 yr ago
      • Reported - view

      Fred I think it may be linked through the dMC ‘Other Data’

      The Dynamic value is:

      let xTemplate := number (‘Other Data’);

      (select Table2)[‘Other Data’ = xTemplate]

      • Sam.1
      • 1 yr ago
      • Reported - view

      Fred 

    • Fred
    • 1 yr ago
    • Reported - view
    Sam said:
    Fred I think it may be linked through the dMC ‘Other Data’
    The Dynamic value is:
    let xTemplate := number (‘Other Data’);
    (select Table2)[‘Other Data’ = xTemplate]

     dMCs do not create a hard link between records, unlike reference fields. They make more of a "soft link" between records. You have to use number(dMC) or record(tablename,number(dMC)) to get the full record.

     

    Sam said:
    The text field is populated from a Dynamic multiple choice field.
    I would like to reference that choice.

     If you are talking about the dMC in table3 that is used to create the records in Table1 then you can if you create the link in the reference field Data Item when you first create the records in table1. Thus my question about why not create the link to Table2 (Data Item) when you create the Table1 records.

    Does this make sense? I'm getting a bit confused talking about it.

    So back to your original question. You can do something as simple as this in the trigger of Data1:

    let t := this;
    'DATA ITEMS'.Data := t.Data1
    

    And this will copy the data from Data1 to Data in the table 'Data Items'.

    Just be aware that subsequent Table1 records that are linked to Table2 will overwrite the previous copy. Will you have multiple records in Table1 linked to a single record in Table2?

      • Sam.1
      • 1 yr ago
      • Reported - view

      Fred Will you have multiple records in Table1 linked to a single record inTable2?

      yes

      • Sam.1
      • 1 yr ago
      • Reported - view

      Sam I’ll double check to be sure.

    • Fred
    • 1 yr ago
    • Reported - view
    Sam said:
    Fred Will you have multiple records in Table1 linked to a single record inTable2?
    yes

     So you can try this:

    let t := this;
    let newData := 'DATA ITEMS'.Data + "
    " + t.Data1;
    'DATA ITEMS'.Data := newD
    

    Now we create a new variable that gathers the data from the Data field in Table2 then adds a paragraph break then adds the data from the Data1 field of the current record.

    Then we copy the data of the new variable into the Data field of Table2.

      • Sam.1
      • 1 yr ago
      • Reported - view

      Fred Fred I’ll let you know how it goes

      thanks

      • Sam.1
      • 1 yr ago
      • Reported - view

      Sam Got the data where I need it!

      Thanks Fred :)

      I used your first 2 suggestions. If I use the last one I'll let you know. 

      • Sam.1
      • 1 yr ago
      • Reported - view

      Sam Im sending this after changing the status to answered. Just curious to see if the thread continues. 

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 18Replies
  • 111Views
  • 2 Following