Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

I have a collection named varDuplicateSuppliers which i want to relate to this record

  1. User

    I have a collection named varDuplicateSuppliers which i want to relate to this record

  2. Assistant

    To relate the collection named varDuplicateSuppliers to a record, you can do the following:

    1. Identify the specific record you want to relate to the collection. Let's say the record's ID is recordID.

    2. Use the relation.push method to add the record's ID to the varDuplicateSuppliers collection. Here's an example:

    // Assuming `varDuplicateSuppliers` is an array collection
    varDuplicateSuppliers.push(recordID);
    

    In this example, the recordID will be added to the varDuplicateSuppliers collection. 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.

  3. User

    i use power fx programming language

  4. Assistant

    In Power FX, you can use a relational operator such as Concat or Union to relate the varDuplicateSuppliers collection 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 Concat function is used to add the record to the varDuplicateSuppliers collection. The UpdateContext function is used to update the variable varDuplicateSuppliers with the new relation.

    You can access this collection later to retrieve the related records using functions like Filter or LookUp.

  5. 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

  6. Assistant

    To relate the item to all items in the varDuplicateSuppliers collection, you can modify the code as follows:

    ForAll(varDuplicateSuppliers,
        Relate(
            paramSelectedPlan.'DOT Trials',
            ThisRecord
        )
    );
    

    In this updated code, the ForAll function is used to iterate through each item in the varDuplicateSuppliers collection. The Relate function is then used to relate the ThisRecord (current record) to the paramSelectedPlan.'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 varDuplicateSuppliers collection.

  7. User

    I need it to relate to the newly created task

  8. Assistant

    To relate the newly created task to all items in the varDuplicateSuppliers collection, 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 the Patch function:

    var newTask = Patch('Outsourcing Tasks', Defaults('Outsourcing Tasks'), { ... });
    

    Next, use the ForAll function to iterate through each item in the varDuplicateSuppliers collection and relate the newTask to each item. Modify your code as follows:

    ForAll(varDuplicateSuppliers,
        Relate(
            paramSelectedPlan.'DOT Trials',
            newTask
        )
    );
    

    In this updated code, the ForAll function is used to iterate through each item in the varDuplicateSuppliers collection. The Relate function is then used to relate the newTask to the paramSelectedPlan.'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 varDuplicateSuppliers collection.

  9. User

    show me how this would be when all code is combined

  10. 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 the varDuplicateSuppliers collection after it has been created.

  11. User

    i want it on each task

  12. Assistant

    Apologies for the confusion. To relate each task individually to all items in the varDuplicateSuppliers collection, 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.SelectedItems is processed individually. For each item, a new task is created using the Patch function, and the reference to that task is stored in the newTask variable. Then, the newTask is related to all items in the varDuplicateSuppliers collection using the ForAll and Relate functions.

    By executing this modified code, each newly created task will be related to all the items in the varDuplicateSuppliers collection individually.

  13. User

    write me all the code

  14. 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 the Patch function to match your requirements as well.

  15. User

    can you put ForAll(varDuplicateSuppliers, Relate( paramSelectedPlan.‘DOT Trials’, newTask for itself

  16. Assistant

    Certainly! Here's the updated code where newTask is related to itself for each item in the varDuplicateSuppliers collection:

    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 newTask to each item in the varDuplicateSuppliers collection, the Relate function is used again to relate newTask to itself for each item in varDuplicateSuppliers. This establishes a self-relationship where each newTask is related to itself. Please ensure that this self-relationship aligns with your data model requirements.