cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Rkaur
Level: Powered On

Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

HI,

im using patch function to create child entity records using parent record identifier passed from a BrowseGallery screen to Detail form screen using child entity as datasource.

 formula i used - 

Patch('Service Tasks',ForAll(ChecklistGallery.AllItems, {xyz_completed : Checkbox3.Value, xyz_tasktype : TaskName.Text, xyz_jobcard :BrowseGallery1.Selected.'Case Title'}))

 

here: xyz_jobcard is the parent record identifier which is available in browsegallery of BrowseScreen.

Clicking on specific record from browse takes me to Detail form screen of that parent record where additionally there is a gallery of a child entity data set requiring some user input in form of checkbox (Yes/No). A button at teh end should patch all my items in child gallery to the parent record. 

Teh above function doesnt seem to work though.

Kindly suggest.

Erro says - "Invalid Argument type (table). Expecting a record value instead.

 

patch function.PNG

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rkaur
Level: Powered On

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

Hi Kris,

 

Thankyou so much for helping out here.

and for identifying the missed "}" curly bracket.

Im able to successfuly push teh records to CRM with PATCH. 

With Collection option, i tried putting my column "Completed" within single quotes and without it also. as mentioned above but probably needs to be checked more not sure whats wrong.

15 REPLIES 15
Community Support Team
Community Support Team

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

Hi @Rkaur ,

Are the xyz_completed column, xyz_tasktype column and  xyz_jobcard column all columns in your 'Service Tasks' Entity?

 

Based on the formula that you provided, I think there is something wrong with it. I have made a test on my side, please consider take a try with the following workaround:

Set the OnSelect property of the "SAVE" button to following formula:

ForAll(
         ChecklistGallery.AllItems,
         Patch(                              /* <-- Create records in your 'Service Tasks' Entity */
                  'Service Tasks',
                   Defaults('Service Tasks'),
                   {
                      xyz_completed: Checkbox3.Value,
xyz_tasktype: TaskName.Text,
xyz_jobcard: BrowseGallery1.Selected.'Case Title' } ) )

Please consider take a try with above solution, then check if the issue is solved.

 

More details about the ForAll function and Patch function, please check the following article:

ForAll function, Patch function

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Rkaur
Level: Powered On

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

Hi,

 

Yes,  xyz_completed (two options) column, xyz_tasktype (lookup) column and  xyz_jobcard(lookup to case record(parent)) column are all defiend as fields in the'Service Tasks' Entity.

 

i tried with the forumula before too by swapping ForAll as teh first function but it doesnt work too.

forall first for patching.PNG

Highlighted
Rkaur
Level: Powered On

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

Hi,

 

i want to highlight the fact that "Service Tasks" is my custom CDS entity. which has been added as a subgrid under Cases.

It contains custom defined : xyz_completed (two options) column, xyz_tasktype (lookup) column and  xyz_jobcard(lookup to case record(parent)) column 

in my screenshot above, as we write Patch and select teh datasource it doesnt highlight that in green color unlike the ususal process. If i choose any otehr datasource name that is shown as green. Is there anything to do with it because of which my function isnt validating.

Please note i have added "service tasks" as a datasource in my powerapp 

Community Support Team
Community Support Team

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

Hi @Rkaur ,

Based on the screenshot that you mentioned, I found that there is something wrong with it. Could you please share more details about the error message within your formula?

 

Based on the issue that you mentioned, I think there is somthing issue with the values you provided for the xyz_completed (two options) column, xyz_tasktype (lookup) column and  xyz_jobcard(lookup to case record(parent)).

 

I have made a test on my side, please take a try with the following formula:

ForAll(
         ChecklistGallery.AllItems,
         Patch(                              /* <-- Create records in your 'Service Tasks' Entity */
                  'Service Tasks',
                   Defaults('Service Tasks'),
                   {
                      xyz_completed: If(CheckBox3.Value = true, 'xyz_completed (EntityName)'.Yes, 'xyz_completed (EntityName)'.No),
xyz_tasktype: LookUp(TaskNameEntity, 'Primary Name' = TaskName.Text),
xyz_jobcard: LookUp(CaseEntity, 'Case Title' = BrowseGallery1.Selected.'Case Title') } ) )

Note: The TaskNameEntity represents the Entity your xyz_tasktype column looks up to. The 'Primary Name' column represents the column in your TaskNameEntity, which used to store the task name value.

 

More details about assigning a value for "Two Options" type column in CDS Entity, please check my response within the following thread:

https://powerusers.microsoft.com/t5/General-Discussion/How-do-I-write-back-to-the-quot-two-option-qu...

Also please and see if the following blog would help in your scenario:

https://powerapps.microsoft.com/en-us/blog/option-sets-and-many-to-many-relationships-for-canvas-app...

 

More details about setting a value for LookUp field in your CDS Entity, please check the following thread:

https://powerusers.microsoft.com/t5/General-Discussion/Patch-a-CDS-Lookup-column-within-PowerApps/m-...

 

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Rkaur
Level: Powered On

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

Hi Kris,

 

i tried your suggestion so i understand there is a different way to write to a Two Options column.

however, i strongly feel the problem is around my datasource name is not highlighted in green. its a custom CDS entity and im on a trial env. anything around it that i should check ?

 

Anyhow - the errors i get is - FUnction ForALl has some invalid arguments, FUnction Patch has some Invalid Arguments

Community Support Team
Community Support Team

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

Hi @Rkaur ,

Could you please share a screenshot about your issue?

 

Please consider modify your formula as below:

ForAll(
         ChecklistGallery.AllItems,
         Patch(                              /* <-- Create records in your 'Service Tasks' Entity */
                  [@'Service Tasks'],                  /* <-- Modify here. Wrapped the data source name with Disambiguation operator (@) */
                   Defaults([@'Service Tasks']),       /* <-- Modify here */
                   {
                      xyz_completed: If(CheckBox3.Value = true, 'xyz_completed (EntityName)'.Yes, 'xyz_completed (EntityName)'.No),
xyz_tasktype: LookUp(TaskNameEntity, 'Primary Name' = TaskName.Text),
xyz_jobcard: LookUp(CaseEntity, 'Case Title' = BrowseGallery1.Selected.'Case Title') } ) )

 

Please take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Rkaur
Level: Powered On

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

Attaching screen shot

forall with@.png

 

variable _varCaseId is set as : BrowseGallery1.Selected.Case ( case records' guid)

overing over red lines say - Fuction ForALl has invalid arguments

Function Patc has Invalid arguments

Rkaur
Level: Powered On

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

HI Kris,

 

i used an alternate way to patch by using COllections.

 

so here on checkbox OnCheck property im creating a collection

Collect(JobTasks,{dsh_completed:Checkbox3.Value,dsh_tasktype:TaskName.Text,dsh_jobcard:_varCaseId})

Then on SUbmit button im passing this collection name to my datasource as a patch alternate.

 

but here i get a warning that column dsh_jobcard doesnt exist

 

collection to patch.png

 

service tasks entity.PNG

 

KIndly assist. i have tries two options : the first option with FORALL and PATCH and the second one with COLLECTION

Community Support Team
Community Support Team

Re: Patch records from child gallery to parent entity record. Related child entity added as a subgrid in parent entity form

Hi @Rkaur ,

Within your Patch formula, please type [@'Service Tasks'] rather than @'Service Tasks'. Your formula should like below:

ForAll(
         ChecklistGallery.AllItems,
         Patch(                              /* <-- Create records in your 'Service Tasks' Entity */
                  [@'Service Tasks'],                  /* <-- Modify here. Do not miss [ ] here */
                   Defaults([@'Service Tasks']),       /* <-- Modify here.  Do not miss [ ] here */
                   {
                      Completed: If(CheckBox3.Value = true, 'xyz_completed (EntityName)'.Yes, 'xyz_completed (EntityName)'.No),
'Task Type': LookUp(TaskNameEntity, 'Primary Name' = TaskName.Text),
'Job Card': LookUp(CaseEntity, 'Case Title' = BrowseGallery1.Selected.'Case Title') } ) )

Note: Within the { } part of your Patch function, please use Display name of the column in your CDS Entity rather than the Logic name (e.g. dsh_completed, dsh_tasktype, ...) 

 

For your second alternative solution, I agree with you. But there are some issues with your Collect function. Please modify your Collect formula as below:

Collect(
JobTasks,
{
Completed: Checkbox3.Value,
'Task Type': TaskName.Text,
'Job Card': _varCaseId
}
)

Please take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

Follow PowerApps on Twitter

Stay Up-to-Date by following PowerApps on Twitter

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 136 members 3,987 guests
Recent signins:
Please welcome our newest community members: