0

Connect 2 Records from 2 Tables, based on 2 or More Parameters

I have 2 Tables, X and Y. Both tables have the data: SKU and Order Num. I want to create a button that will automatically link the records tables X and Y if the record has the same SKU and Order Num. Is there a way to do this, even for multiple parameters? Thanks!

5 replies

null
    • John_Halls
    • 2 yrs ago
    • Reported - view

    Hi Borgir!

     

    Yes, this can be achieved with a script, either one record at a time or en-mass. You need to decide which of X and Y is going to act as the parent. If SKU plus Order Num is unique you will be able to see the correct information from both sides. If SKU plus Order Num is not unique then you will be seeing the correct information from the parent side, but it won't look right from the child side unless a join table is included to make it a many-to-many join.

     

    Can I ask why you have two tables both holding such similar data?

     

    Regards John

    • UX
    • Borgir
    • 2 yrs ago
    • Reported - view

    Hi I'm sorry, I was making this post in a hurry. Let me explain this:

    So, we have 2 tables - Raw Shipment ID and Raw PI ID. We work with both our distributor side and supplier side, that's why we have 2 tables PI- being the orders on our supplier side, and Shipments on our distributor side.

    We can't restructure or combine these two tables as different teams (which work independently) work on each table, so restructuring them would burn more time than we can save.

    Now, for the 'Raw PI ID' table, we have a "PI" and the product ID represented by the column "SKU".

    For the Shipment ID table, each shipment line item still has a "PI" column (but since the PI can be split into multiple shipments, the PI can change in nomenclature, ie. PI 1 from the table 'Raw PI ID' can be split into USA and Canada shipments, which when translated on the 'Shipment ID' table becomes, PI 1 USA and PI 1 CA). Also it has an SKU field.

    These PI orders can be split into multiple shipment IDs. Essentially, it's a 1:N, Raw PI ID : Raw Shipment ID table relationship. 

    My current solution:

    -Firstly, since the "PI" on the shipment table can be added with other characters (PI USA, PI CA, etc), it can just be remedied by slicing the PI data into different arrays through their spaces, and then extracting the first word on the array, which would be the root PI ID.

    -Next, since I don't want to deal with "and" qualifiers, and since the SKU-PI ID is unique, I can just concatenate both columns into a single array, thereby producing a unique SKU-PI column, reducing the parameter to match into 1 instead of 2. I named this "SKU-PI ID" pairing column into "LINK" (from the Shipments table) and "LINK 2" (from the PI ID table). 

    -I then created a button trigger (on the shipments table) that when pressed will link the item from the matching records from the shipments table to the PI ID table when clicked. Again, this button is on the shipments table:

    let x := this.LINK;
    let y := last((select 'Raw PI ID' where 'LINKER 2' = x).Id);
    'Raw PI ID' := y

    Here's what I want to ask help for:

    Suppose we have 1,000 new records uploaded by CSV, it would be logistically impossible to religiously click the button for each of the 1,000 new records.

    Is there a way to make a button that initiates a loop that matches the record from the Raw Shipment ID table to the RAW PI ID table, given LINKER as the concatenated column for the SKU and PI Id?

    Thanks!

    • Alain_Fontaine
    • 2 yrs ago
    • Reported - view

    Updating many records is a job for the… "Update multiple records… " command. A detailed explanation can be found here: https://forum.ninox.com/t/h7hrzwn?r=60hraz0

    • Sean
    • 2 yrs ago
    • Reported - view

    Well, that is one way. 😉 

    https://forum.ninox.com/t/q6hrt98

    • Fred
    • 2 yrs ago
    • Reported - view

    I don't know if putting your button code into the formula of a multiple record update would work, but that is an option to try. Depends on how often you need to import records then modify them.

    Here is something off the top of my head for a button as I don't have a DB setup like yours.

    for loop1 select Shipments['Raw PI ID' = null] do
        let x := loop1.LINK;
        let y := last(select 'Raw PI ID' where 'LINKER 2' = x);
        loop1.('Raw PI ID' := y)

    end

    Since you have a working button you just need to modify it a bit to work within a loop.

    First you have to find the records that you have just imported. My guess is that the field 'Raw PI ID' is blank upon an import, so I'm using that.

    Then you just need to put the loop variable in the proper places so Ninox knows where to get the right data.

    This should get you started. Good luck and let us know how it goes.

Content aside

  • 2 yrs agoLast active
  • 5Replies
  • 497Views
  • 4 Following