Hi
I have been developing apps in Outsystems for a few years, but I still consider myself a beginner. I have 1 entity for devices (Racelinks) and 1 entity for people (Competitors). There is a 1 to many relationship, 1 user can have many devices. For each new event I upload user information. I am trying to get my app to allocate 1 device to each user. The server action I created currently allocates all devices to one user. Can anyone point me in the right direction?
Hey @Derek Fleming ,
The problem could be on the assign you are doing.Are you using:GetRacelinks.List.Current.Racelink.AllocatedTo = GetCompetitors.List[GetRacelinks.List.CurrentRowNumber].Competitor.Id
(CORRECT)OR
GetRacelinks.List.Current.Racelink.AllocatedTo = GetCompetitors.List.Current.Competitor.Id
(INCORRECT)
If you are using the latter, the competitor will always be the same as it is not being iterated.
The value should be:
GetCompetitors.List[GetRacelinks.List.CurrentRowNumber].Competitor.Id Also, the start index on the loop should be 0.So it always start from the beggining.
Doest it makes sense?
Best Regards,
RR :)
Hi @Derek Fleming
If you want to assign one device to each users firstly apply loop on Competitors after that get one by one device and assign it into Competitors entity and update it .
Like below
GetRaceLinks.List[GetCompetitors.List.CurrentRowNumber].DeviceId
Regards ,
Rajat
Thanks for the reply Rajat. I'm not sure that will work, maybe my data model is the wrong way round. The foreign key for this relationship is in the Racelink entity
Hi Rajat
I tried this in the foreach Record list attributeGetRacelinks.List[GetCompetitors.List.CurrentRowNumber].Racelink.Id
I received this error message'Record List' data type required instead of 'Racelink Identifier'.
Hi,
You need to iterate over both GetRacelinks.List and GetCompetitors.List simultaneously, ensuring you assign each Racelink to one Competitor. If you have more devices than users, you may want to cycle through the users repeatedly.
Thank you for the reply. Yes I agree, my head tells me that's what I need to do. Just not sure how to go about it in Outsystems.
Hey @Derek Fleming,
I'm not sure if I completely understand your use case.
However, assuming that Racelinks don’t need to be validated to check if they are already allocated, and that you will always have enough devices for everyone, here is one possible approach:
GetRacelinks.List.Current.Racelink.AllocatedTo = GetCompetitors.List[GetRacelinks .List.CurrentRowNumber].Competitor.Id
This is one way to solve it.
If you want to optimize it even further, you could use advanced SQL to perform the operation in a single transaction, avoiding multiple updates.
It might also be worth to revisit the data model as you said previously to ensure you have the correct modeling for your needs.
Let me know if it helps,Best Regards,RR :)
Hi Raphael
I think I am getting close, thank you for your reply and help. I know have the App allocating the correct number of Racelinks but they are still being allocated to 1 user. I am obviously doing something wrong but I'm not sure what it is. Could it be to do with the Source attribute in the Update operation?
Here is screen shots to give you more context
Data Model
Logic
Result (User data is dummy data)
Hi RR
Thank you so much, as a result of your help and advice I was able to get this working perfectly. TY TY TY