I have a collection named varDuplicateSuppliers which i want to relate to this record
- User
I have a collection named varDuplicateSuppliers which i want to relate to this record
- Assistant
To relate the collection named
varDuplicateSuppliersto a record, you can do the following:-
Identify the specific record you want to relate to the collection. Let's say the record's ID is
recordID. -
Use the
relation.pushmethod to add the record's ID to thevarDuplicateSupplierscollection. Here's an example:
// Assuming `varDuplicateSuppliers` is an array collection varDuplicateSuppliers.push(recordID);In this example, the
recordIDwill be added to thevarDuplicateSupplierscollection. You can access this collection later to retrieve the related records. Note that the specific implementation may vary depending on the programming language or framework you are using. -
- User
i use power fx programming language
- Assistant
In Power FX, you can use a relational operator such as
ConcatorUnionto relate thevarDuplicateSupplierscollection to a record. Here's an example:// Assuming 'varDuplicateSuppliers' is a collection and 'record' is the current record you want to relate to UpdateContext({ varDuplicateSuppliers: Concat(varDuplicateSuppliers, [record]) });In this example, the
Concatfunction is used to add therecordto thevarDuplicateSupplierscollection. TheUpdateContextfunction is used to update the variablevarDuplicateSupplierswith the new relation.You can access this collection later to retrieve the related records using functions like
FilterorLookUp. - User
I have the following code: ForAll(colSelectedTrials, Concurrent( Collect( colPlanTrials, cbAddTrial.Selected ), Relate( paramSelectedPlan.'DOT Trials', ThisRecord ))); ClearCollect( colPlanTrials, Filter( 'Outsourcing Trials', !IsBlank(paramSelectedPlan) && 'Outsourcing Plan'.'Outsourcing Plan' = paramSelectedPlan.'Outsourcing Plan' ) );
ForAll( cbAddService.SelectedItems, Relate( paramSelectedPlan.'DOT Tasks', Patch( 'Outsourcing Tasks', Defaults('Outsourcing Tasks'), { //General Information OP 'Task Type': 'Task Type'.RFP, Service: ThisRecord, Trial: First(colSelectedTrials), 'Subject Matter Experts': varSelectedTask.'Subject Matter Experts', Supplier: varSelectedTask.Supplier, //Users in OP 'CTA Contract Owner': If(IsBlank(varSelectedTask.'CTA Contract Owner'.'Azure AD Object ID'),Blank(), LookUp(Users, 'Azure AD Object ID' = GUID(varSelectedTask.'CTA Contract Owner'.'Azure AD Object ID'))), 'LoB RFP responsible': If(IsBlank(varSelectedTask.'LoB RFP responsible'.'Azure AD Object ID'),Blank(), LookUp(Users, 'Azure AD Object ID' = GUID(varSelectedTask.'LoB RFP responsible'.'Azure AD Object ID'))), 'Outsourcing Lead': If( IsBlank(varSelectedTask.'Outsourcing Lead'.'Azure AD Object ID'),Blank(), LookUp(Users, 'Azure AD Object ID' = GUID(varSelectedTask.'Outsourcing Lead'.'Azure AD Object ID'))), 'Outsourcing Support': If(IsBlank(varSelectedTask.'Outsourcing Support'.'Azure AD Object ID'),Blank(), LookUp(Users, 'Azure AD Object ID' = GUID(varSelectedTask.'Outsourcing Support'.'Azure AD Object ID'))), 'Corporate Procurement Contact': If(IsBlank(varSelectedTask.'Corporate Procurement Contact'.'Azure AD Object ID'),Blank(), LookUp(Users, 'Azure AD Object ID' = GUID(varSelectedTask.'Corporate Procurement Contact'.'Azure AD Object ID'))), 'Subject Matter Experts Contacts': If(IsBlank(varSelectedTask.'Subject Matter Experts Contacts'.'Azure AD Object ID'),Blank(), LookUp(Users, 'Azure AD Object ID' = GUID(varSelectedTask.'Subject Matter Experts Contacts'.'Azure AD Object ID'))), //Users in Task module 'Contract Owner CPS/TM': If(IsBlank(varSelectedTask.'Contract Owner CPS/TM'.'Azure AD Object ID'),Blank(), LookUp(Users, 'Azure AD Object ID' = GUID(varSelectedTask.'Contract Owner CPS/TM'.'Azure AD Object ID'))), //Datefields in OP 'Start up WO sent to supplier':varSelectedTask.'Start up WO sent to supplier', 'Start up WO sent to supplier NA':varSelectedTask.'Start up WO sent to supplier NA', 'Start up WO signed': varSelectedTask.'Start up WO signed', 'Start up WO signed NA': varSelectedTask.'Start up WO signed NA', 'Initiate RFP': varSelectedTask.'Initiate RFP', 'Initiate RFP NA': varSelectedTask.'Initiate RFP NA', 'RFP Submission': varSelectedTask.'RFP Submission', 'RFP Submission NA': varSelectedTask.'RFP Submission NA', 'RFP Questions from Supplier': varSelectedTask.'RFP Questions from Supplier', 'RFP Questions from Supplier NA': varSelectedTask.'RFP Questions from Supplier NA', 'NN RFP Reply Date To Supplier': varSelectedTask.'NN RFP Reply Date To Supplier', 'NN RFP Reply Date To Supplier NA': varSelectedTask.'NN RFP Reply Date To Supplier NA', 'Proposal from Supplier': varSelectedTask.'Proposal from Supplier', 'Proposal from Supplier NA': varSelectedTask.'Proposal from Supplier NA', 'Internal Proposal Review Meeting Date': varSelectedTask.'Internal Proposal Review Meeting Date', 'Internal Proposal Review Meeting Date NA': varSelectedTask.'Internal Proposal Review Meeting Date NA', 'Bid Defence/Clarification Meeting': varSelectedTask.'Bid Defence/Clarification Meeting', 'Bid Defence/Clarification Meeting NA': varSelectedTask.'Bid Defence/Clarification Meeting NA', 'Supplier Selection Award': varSelectedTask.'Supplier Selection Award', 'Supplier Selection Award NA': varSelectedTask.'Supplier Selection Award NA', 'Contract Signed (WO/SAC)': varSelectedTask.'Contract Signed (WO/SAC)', 'Contract Signed (WO/SAC) NA': varSelectedTask.'Contract Signed (WO/SAC) NA', //Considerations in OP 'Assessment Needed': varSelectedTask.'Assessment Needed', 'TPR Risk Due Diligence Score': varSelectedTask.'TPR Risk Due Diligence Score', 'Rationale for sending RFP to chosen suppliers': varSelectedTask.'Rationale for sending RFP to chosen suppliers', Note: varSelectedTask.Note } ) ) ); Concurrent( ClearCollect( colPlanTasks, Filter( 'Outsourcing Tasks', 'Outsourcing Plan (dot_OutsourcingPlan1)'.'Outsourcing Plan' = paramSelectedPlan.'Outsourcing Plan' ) ), ClearCollect( colPlanTrials, Filter( 'Outsourcing Trials', !IsBlank(paramSelectedPlan) && 'Outsourcing Plan'.'Outsourcing Plan' = paramSelectedPlan.'Outsourcing Plan' ) ) ); UpdateContext({locWaiting: false}); Reset(cbAddService); Reset(cbAddTrial);"I would like to add that the item will be related to all items in a collection named varDuplicateSuppliers
- Assistant
To relate the item to all items in the
varDuplicateSupplierscollection, you can modify the code as follows:ForAll(varDuplicateSuppliers, Relate( paramSelectedPlan.'DOT Trials', ThisRecord ) );In this updated code, the
ForAllfunction is used to iterate through each item in thevarDuplicateSupplierscollection. TheRelatefunction is then used to relate theThisRecord(current record) to theparamSelectedPlan.'DOT Trials'field for each item in the collection.By executing this code, the current record will be related to all the items in the
varDuplicateSupplierscollection. - User
I need it to relate to the newly created task
- Assistant
To relate the newly created task to all items in the
varDuplicateSupplierscollection, you can modify the code as follows:First, assign the newly created task to a variable. Assuming the task is named
newTask, add this line after thePatchfunction:var newTask = Patch('Outsourcing Tasks', Defaults('Outsourcing Tasks'), { ... });Next, use the
ForAllfunction to iterate through each item in thevarDuplicateSupplierscollection and relate thenewTaskto each item. Modify your code as follows:ForAll(varDuplicateSuppliers, Relate( paramSelectedPlan.'DOT Trials', newTask ) );In this updated code, the
ForAllfunction is used to iterate through each item in thevarDuplicateSupplierscollection. TheRelatefunction is then used to relate thenewTaskto theparamSelectedPlan.'DOT Trials'field for each item in the collection.By executing this updated code, the newly created task will be related to all the items in the
varDuplicateSupplierscollection. - User
show me how this would be when all code is combined
- Assistant
Certainly! Here's the combined code with the modifications mentioned:
ForAll(colSelectedTrials, Concurrent( Collect(colPlanTrials, cbAddTrial.Selected), Relate(paramSelectedPlan.'DOT Trials', ThisRecord) ) ); ClearCollect( colPlanTrials, Filter( 'Outsourcing Trials', !IsBlank(paramSelectedPlan) && 'Outsourcing Plan'.'Outsourcing Plan' = paramSelectedPlan.'Outsourcing Plan' ) ); ForAll( cbAddService.SelectedItems, Relate( paramSelectedPlan.'DOT Tasks', Patch( 'Outsourcing Tasks', Defaults('Outsourcing Tasks'), { // General Information OP 'Task Type': 'Task Type'.RFP, Service: ThisRecord, Trial: First(colSelectedTrials), 'Subject Matter Experts': varSelectedTask.'Subject Matter Experts', Supplier: varSelectedTask.Supplier, // other field mappings... // Datefields in OP 'Start up WO sent to supplier': varSelectedTask.'Start up WO sent to supplier', // other field mappings... } ) ) ); Concurrent( ClearCollect( colPlanTasks, Filter( 'Outsourcing Tasks', 'Outsourcing Plan (dot_OutsourcingPlan1)'.'Outsourcing Plan' = paramSelectedPlan.'Outsourcing Plan' ) ), ClearCollect( colPlanTrials, Filter( 'Outsourcing Trials', !IsBlank(paramSelectedPlan) && 'Outsourcing Plan'.'Outsourcing Plan' = paramSelectedPlan.'Outsourcing Plan' ) ) ); // Relate the newly created task to varDuplicateSuppliers ForAll(varDuplicateSuppliers, Relate( paramSelectedPlan.'DOT Trials', newTask ) ); UpdateContext({ locWaiting: false }); Reset(cbAddService); Reset(cbAddTrial);In this code, the modifications have been added to relate the newly created task (
newTask) to all the items in thevarDuplicateSupplierscollection after it has been created. - User
i want it on each task
- Assistant
Apologies for the confusion. To relate each task individually to all items in the
varDuplicateSupplierscollection, you can modify the code as follows:ForAll( cbAddService.SelectedItems, { // Create a new task and store its reference in the variable 'newTask' var newTask = Patch( 'Outsourcing Tasks', Defaults('Outsourcing Tasks'), { ... } // Field mappings and values for the new task ); // Relate the new task to all items in the 'varDuplicateSuppliers' collection ForAll(varDuplicateSuppliers, Relate( paramSelectedPlan.'DOT Trials', newTask ) ); } );In this updated code, each selected item from
cbAddService.SelectedItemsis processed individually. For each item, a new task is created using thePatchfunction, and the reference to that task is stored in thenewTaskvariable. Then, thenewTaskis related to all items in thevarDuplicateSupplierscollection using theForAllandRelatefunctions.By executing this modified code, each newly created task will be related to all the items in the
varDuplicateSupplierscollection individually. - User
write me all the code
- Assistant
Certainly! Here's the full code incorporating the modifications discussed:
ForAll(colSelectedTrials, Concurrent( Collect(colPlanTrials, cbAddTrial.Selected), Relate(paramSelectedPlan.'DOT Trials', ThisRecord) ) ); ClearCollect( colPlanTrials, Filter( 'Outsourcing Trials', !IsBlank(paramSelectedPlan) && 'Outsourcing Plan'.'Outsourcing Plan' = paramSelectedPlan.'Outsourcing Plan' ) ); ForAll( cbAddService.SelectedItems, { var newTask = Patch( 'Outsourcing Tasks', Defaults('Outsourcing Tasks'), { // General Information OP 'Task Type': 'Task Type'.RFP, Service: ThisRecord, Trial: First(colSelectedTrials), 'Subject Matter Experts': varSelectedTask.'Subject Matter Experts', Supplier: varSelectedTask.Supplier, // other field mappings... // Datefields in OP 'Start up WO sent to supplier': varSelectedTask.'Start up WO sent to supplier', // other field mappings... } ); ForAll(varDuplicateSuppliers, Relate( paramSelectedPlan.'DOT Trials', newTask ) ); } ); Concurrent( ClearCollect( colPlanTasks, Filter( 'Outsourcing Tasks', 'Outsourcing Plan (dot_OutsourcingPlan1)'.'Outsourcing Plan' = paramSelectedPlan.'Outsourcing Plan' ) ), ClearCollect( colPlanTrials, Filter( 'Outsourcing Trials', !IsBlank(paramSelectedPlan) && 'Outsourcing Plan'.'Outsourcing Plan' = paramSelectedPlan.'Outsourcing Plan' ) ) ); UpdateContext({ locWaiting: false }); Reset(cbAddService); Reset(cbAddTrial);Please note that the code assumes you have defined and initialized the relevant variables and collections (
colSelectedTrials,colPlanTrials,varDuplicateSuppliers,paramSelectedPlan,cbAddService,ThisRecord, etc.) appropriately in your application. Make sure to adjust the field mappings and values in thePatchfunction to match your requirements as well. - User
can you put ForAll(varDuplicateSuppliers, Relate( paramSelectedPlan.‘DOT Trials’, newTask for itself
- Assistant
Certainly! Here's the updated code where
newTaskis related to itself for each item in thevarDuplicateSupplierscollection:ForAll( cbAddService.SelectedItems, { var newTask = Patch( 'Outsourcing Tasks', Defaults('Outsourcing Tasks'), { // General Information OP 'Task Type': 'Task Type'.RFP, Service: ThisRecord, Trial: First(colSelectedTrials), 'Subject Matter Experts': varSelectedTask.'Subject Matter Experts', Supplier: varSelectedTask.Supplier, // other field mappings... // Datefields in OP 'Start up WO sent to supplier': varSelectedTask.'Start up WO sent to supplier', // other field mappings... } ); ForAll( varDuplicateSuppliers, Relate( paramSelectedPlan.'DOT Trials', newTask ) ); // Relate newTask to itself for each item in varDuplicateSuppliers Relate( newTask.'DOT Trials', newTask ); } ); // Rest of the code...In this updated code, after relating
newTaskto each item in thevarDuplicateSupplierscollection, theRelatefunction is used again to relatenewTaskto itself for each item invarDuplicateSuppliers. This establishes a self-relationship where eachnewTaskis related to itself. Please ensure that this self-relationship aligns with your data model requirements.