0

Import into Dynamic Multiple Choice from matched records using IDs - not quite working

I'm pretty sure I'm close. I've done a lot of reading and hours messing around with this.

I am importing some CSV data from another system export into my database here. I have a field in my form that will hold the text names of Pets with commas between them.

I have a DMC field I want to get this data into:

And each record has some associated Pets linked through their common Client:

I've written some code to find the IDs of the Pets in This Client's Pets (above) that have the same name as the names in the PETS TO BE SCHEDULED field (above). I'm pretty sure this works as I've tested displaying the IDs and they match the IDs of the pets in the main Pets table.

However, when I try to make my * Scheduled Pets DMC field match the list of determined IDs, it doesn't work.

I know I'm close.

    for r in select Appointments do
        let availPetIDs := r.'* Client'.Pets;
        let showname := "";
        let incomingPetNames := split(r.'PETS TO BE SCHEDULED', ",");
        let chosenPetIDs := [];
        for incomingPetName in incomingPetNames do
            for availPetID in availPetIDs do
                if availPetID.'* Pet Name' = incomingPetName then
                    chosenPetIDs := record(Pets,availPetID)
                end
            end
        end;
        r.('* Scheduled Pets' := chosenPetIDs)
    end

 

And I also tried:

    for r in select Appointments do
        let availPetIDs := r.'* Client'.Pets;
        let showname := "";
        let incomingPetNames := split(r.'PETS TO BE SCHEDULED', ",");
        let chosenPetIDs := [];
        for incomingPetName in incomingPetNames do
            chosenPetIDs := for availPetID in availPetIDs do
                    if availPetID.'* Pet Name' = incomingPetName then
                        record(Pets,availPetID)
                    end
                end
        end;
        r.('* Scheduled Pets' := chosenPetIDs)
    end

and this:

    for r in select Appointments do
        let availPetIDs := r.'* Client'.Pets;
        let showname := "";
        let incomingPetNames := split(r.'PETS TO BE SCHEDULED', ",");
        let chosenPetIDs := [];
        chosenPetIDs := for availPetID in availPetIDs do
                for incomingPetName in incomingPetNames do
                    if availPetID.'* Pet Name' = incomingPetName then
                        record(Pets,availPetID)
                    end
                end
            end;
        r.('* Scheduled Pets' := chosenPetIDs)
    end

 

What am I missing?

1 reply

null
    • Kent_Signorini
    • 1 yr ago
    • Reported - view

    I got it working! Here's my solution:

        for r in select Appointments do
            let availPetIDs := r.'* Client'.Pets;
            let incomingPetNames := split(r.'PETS TO BE SCHEDULED', ",");
            let chosenPetIDs := for availPetID in availPetIDs do
                    for incomingPetName in incomingPetNames do
                        if availPetID.'* Pet Name' = xvPetName then
                            record(Pets,availPetID)
                        end
                    end
                end;
            r.('* Scheduled Pets' := chosenPetIDs)
        end
    

    The only change was to remove the creation of the chosenPetIDs prior to using it to store the values, and used a let to have the loop actually create the array and not just add to it. I don't know why that matters, but it works now. This language has some mysteries to me compared to other languages I've used.

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 1Replies
  • 54Views
  • 1 Following