0

Button to copy field entries from one field to another (running through entire table)

I have decided it will be better for some data in my system to sit within a subtable. As a result, I would like to copy the entries for certain fields into the new (identically named) fields within the new subtable.

I once found the code for a button that enabled me to do this for my whole workflow before, but can't find it again now...can anyone help please?

__

Master Database is called 'Workflow' (originally based upon the Ninox Project Management' template, but now in no way resembling it.

New Subtable is called 'Bike'

Fields to be copied over (and then deleted from the main table once successful):

Bike /Item

Main Colour

Serial #

Items Received

OTHER / Additional / Excluded (missing) Parts

 

The code I have (below) successfully performs this, but only for the single entry open when the button is triggered. I need it to run through all 926 records in the database. What have I done wrong?

let key := this;
let a := 'Bike / Item';
let b := 'Main Colour (Bike / Item)';
let c := 'Serial #';
let d := 'Items Received';
let e := 'OTHER / Additional / Excluded (missing) Parts';
let t := (create Bike);
Bike.('Bike Primary Key' := t.Id);
t.(Workflow := key);
t.('Bike / Item' := a);
t.('Main Colour' := b);
t.('Serial #' := c);
t.('Items Received' := d);
t.('OTHER / Additional / Excluded (missing) Parts' := e)

6 replies

null
    • T_Bartzsch
    • 3 yrs ago
    • Reported - view

    Hi Anna....

    if this function runs successfully on a buttonclick in one entry, then you can easily paste this code into an loop

     

    for p in select Workflow do 

    p.(

    YOUR CODE

    )

    end

     

    For every entry in Table Workflow it will perform the code within the brackets. in your example:

     

    for p in select Workflow do 

    p.(

    let key := this;
    let a := 'Bike / Item';
    let b := 'Main Colour (Bike / Item)';
    let c := 'Serial #';
    let d := 'Items Received';
    let e := 'OTHER / Additional / Excluded (missing) Parts';
    let t := (create Bike);
    Bike.('Bike Primary Key' := t.Id);
    t.(Workflow := key);
    t.('Bike / Item' := a);
    t.('Main Colour' := b);
    t.('Serial #' := c);
    t.('Items Received' := d);
    t.('OTHER / Additional / Excluded (missing) Parts' := e)

    )

    end

    • John_Halls
    • 3 yrs ago
    • Reported - view

    I know "this" is a reference to the current record but can I ask what the line let key := this does? There's no mention of the variable key anywhere else.

     

    Thanks John

    • T_Bartzsch
    • 3 yrs ago
    • Reported - view

    If you have an subtable, this needs to be connected to the main table. Therefore you assign within the subtable the new generated record to the Maintables ID. If not, you only create another entry in the subtable but its not visible - cause its not connected.

    • Sean
    • 3 yrs ago
    • Reported - view

    t.(Workflow := key);

    • Anna_Wenlock
    • 3 yrs ago
    • Reported - view

    Thanks everyone, I have created this, and it works!

    for i in select Workflow do
    let a := i.'Bike / Item';
    let b := i.'Main Colour (Bike / Item)';
    let c := i.'Serial #';
    let d := i.'Items Received';
    let e := i.'OTHER / Additional / Excluded (missing) Parts';
    let f := i.'Workflow Id';
    let i := (create Bike);
    i.('Bike / Item' := a);
    i.('Main Colour' := b);
    i.('Serial #' := c);
    i.('Items Received' := d);
    i.('OTHER / Additional / Excluded (missing) Parts' := e);
    i.(Workflow := f)
    end

    • John_Halls
    • 3 yrs ago
    • Reported - view

    Thaks Sean. I missed that!

Content aside

  • 3 yrs agoLast active
  • 6Replies
  • 985Views