cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ALS
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
v-bofeng-msft
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
v-bofeng-msft
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

ALS
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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (27,692)