Help with foreach, on a map or cdt, from related records.

Hello, I require your support, well, I have a problem, or rather a very big doubt, is it possible to do a foreach to get data from related records?


For example:
supposing I have the following records:
Record Person
Record Address
Record Account
Record idRelationship

the record idRelationship record will help me to relate the other records by means of an id. so far so good, (I hope I understand)

then, I need to make an expression rule that will bring me the ordered data for a cdt, or a map, 'this is for formatting purposes'.

what i am doing is relating my records, and inserting data,

I am first sorting them by local variables
localVariables(
local!relationship:rule....(relationship: Record idRelationship....)
local!getOwner:{
Record Person
Record Address
Record Account
}
local!getBenef:{
Record Person
Record Address
Record Account
}
is something like this, so after I do my indexing, what I do is create another local variable that does my foreach, but for each 'beneficiary' that I have that I have related in my Record idRelationship table,

for example...

local!iteration:enumerate(length(local!getBenef))+1
and I create a foreach


local!beneficiaries:a!foreach(
items:local!iteration,
expression:type!cdt{
..
..
..
birthDt:index(local!getBenef,Record Person.dateBirth,null)
..
...

}
)

)


something like this would be my code, supposing I have 2 persons data that are in my table, related to my record, I am getting a result like this ....


type!cdt{
dateBirth: 2/21/1998; 8/12/2004;
}
type!cdt{
dateBirth: 2/21/1998; 8/12/2004;
}

when I require them to be like this

type!cdt{
dateBorn: 8/12/2004,
}
type!cdt{
dateBorn: 2/21/1998,
}



additional, I attach an example of a photograph... 

screenshot

is there another way to do it, or am I indexing wrong? I hope I'm making myself clear, I'm a bit frustrated... I really appreciate you reading this far .... thank you!

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    I am confused and think this needs some more explanation. 

  • Hello Stefan,

    I apologize for any confusion. Let me explain my issue concisely. In my Appian application, I’m using a foreach loop to process data from related records. However, instead of mapping the data correctly, I’m encountering a problem where two data points are being printed in a single field, rather than being assigned to their respective maps.

    Here’s the context:

    1. I’m retrieving data for a person, which includes attributes such as:

      • Name
      • Address
      • City
    2. Each attribute has its own record, and there’s a relationship between these records based on an ID.

    3. From this relationship, I have two sets of data (two names, two addresses, and two cities).

    4. My goal is to create two separate maps, each containing the relevant data. I’ve already parameterized the map structure as follows:

    local!benefits := {
      nombre: null,
      domicilio: null,
      ciudad: null
    };
    
    1. Within a foreach loop, I’m trying to generate these maps. However, the current result duplicates the data in each field, when I actually need only one data point per map.

    For example, the output I’m getting is:

    map(
      nombre: Charles; Xavier
      domicilio: Calle numero 1; Calle numero 2
      ciudad: Chicago; NYC
    )
    map(
      nombre: Xavier; Charles
      domicilio: Calle Numero 2; Calle Numero 1
      ciudad: NYC; Chicago
    )
    But I want it to be:
    
    map(
      nombre: Charles
      domicilio: Calle numero 1
      ciudad: Chicago
    )
    map(
      nombre: Xavier
      domicilio: Calle Numero 2
      ciudad: NYC
    )

    Could you please guide me on how to achieve the desired result? Thank you for your assistance!

  • I just saw that with an fv!item it is solved...