cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Copy N:N related records into a collection

Hello,

 

I have a collection of "Specifications" that are in an N:N relationship with "Limits".  The collection of Specs is a subset of the entire Specifications table.  I am trying to create a separate collection that contains all the distinct Limits associated with the subset of Specifications.

 

SpecsLimits Collection
XA, B, C--->A
YC, D B
ZA, C C
   D

 

The CDS entity for Specification has a N:N relationship with Limits through a relationship named "Limits".

 

I have tried a number of ways to collect all of the associated Limits, but they all result in a "The specified column is not accessible in this context" error.

 

 

 

Clear(colLimits);
ForAll(Specs as Spec, Collect(colLimits, Spec.Limits.ID));

Clear(colLimits);
ForAll(Specs as Spec, ForAll(Spec.Limits as Limit, Collect(colLimits, Limit.ID)));

AddColumns(Specs as Spec, "Limits Entries", Spec.Limits.ID);

 

 

 

I have no issue finding the distinct items once I can get the individual Limits into a collection.

 

Any suggestions on how to get all the N:N related items into a collection?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @ALS :

I have tried using ForAll, but it always shows an error. Finally I used a timer control to solve this problem.Please try this solution.

1.JPG2.JPG

1\Add a timer control and set

Duration

 

50 /*loop in 0.05s*/

 

OnSelect

 

Set(TheCount,1);Set(TheEnd,CountRows(Specifications.Name));Clear(colLimits)

 

OnTimerEnd

 

Collect(colLimits,Last(FirstN(Specifications,TheCount)).Limits.Name);Set(TheCount,TheCount+1)

 

Repeat

 

TheCount<=TheEnd

 

 2\Add a data table control and set it's Items proeprty to

 

Distinct(colLimits,Name)

 

15.gif

Best Regards,

Bof

 

View solution in original post

2 REPLIES 2
Community Support
Community Support

Hi @ALS :

I have tried using ForAll, but it always shows an error. Finally I used a timer control to solve this problem.Please try this solution.

1.JPG2.JPG

1\Add a timer control and set

Duration

 

50 /*loop in 0.05s*/

 

OnSelect

 

Set(TheCount,1);Set(TheEnd,CountRows(Specifications.Name));Clear(colLimits)

 

OnTimerEnd

 

Collect(colLimits,Last(FirstN(Specifications,TheCount)).Limits.Name);Set(TheCount,TheCount+1)

 

Repeat

 

TheCount<=TheEnd

 

 2\Add a data table control and set it's Items proeprty to

 

Distinct(colLimits,Name)

 

15.gif

Best Regards,

Bof

 

View solution in original post

Frequent Visitor

Thanks Bof!

 

This is a strange solution, but it works perfectly.

 

I would be interested in knowing if there is a way to do this without a timer, but for now this exactly what I needed!

Helpful resources

Announcements
secondImage

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

Top Kudoed Authors
Users online (29,893)