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

Patch specific record CDS

Hi,

 

I'd like to use Patch to modify a specific record in a CDS table, i use the below syntax to create a new record:

 

Patch('CDS Table',Defaults('CDS Table'),
         {CDSColumn1: TextInput.text,CDSColumn2:DatePicker1.SelectedDate})

What syntax should be used to patch a specific record in that CDS table? (i have the CDS record ID for that specific record)

 

Thanks!

7 REPLIES 7
RaninHa
Level: Powered On

Re: Patch specific record CDS

Correction: 

Patch('CDS Table',Defaults('CDS Table'),

         {CDSColumn1: TextInput.text,
          CDSColumn2: D
atePicker1.SelectedDate})

PytByt
Level 8

Re: Patch specific record CDS

Hi @RaninHa 

Have you solved the problem?

If yes, how you solved it? 

 

Can i have the patch formula you used to solved the problem please?

Thanks,

BR.
Pytbyt

Super User
Super User

Re: Patch specific record CDS

Hi @PytByt 

You have an error in the second element of your Patch() function if you want to patch a record in your entity.  

Patch('CDS Table',Defaults('CDS Table'),
         {CDSColumn1: TextInput.text,
          CDSColumn2: DatePicker1.SelectedDate})

 Defaults(datasource) is only used for adding a new record.  To patch an already existing record you need to specify it.  For example, if you want to patch a record in a gallery, you would use something like:

Patch('CDS Table',Lookup('CDS Table', ID=Gallery1.Selected.ID),
         {CDSColumn1: TextInput.text,
          CDSColumn2: DatePicker1.SelectedDate})

To specify the record being patched.  Refer to  https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

PytByt
Level 8

Re: Patch specific record CDS

Hi @Drrickryp 

I'm using thi formula to update my existing records in CDS, but no luck.

The formula doesnt seems work at all for patching new or update the existing record.

Patch('SMU_Service Line', LookUp('SMU_Service Line', cr1e4_key = LabelKeyRejectedInspection.Text),
{cr1e4_responds: RadioRespondsRejectectedInspection.Selected.Value,
cr1e4_respondtext: TextInputQuestionRejectedInspection.Text,
cr1e4_remarks: TextInputRemarksRejectedInspection.Text});

I'm trying to patch an update to an existing record in my cds trough my gallery items here:
patch existing cds 1.png

When i use ForAll function along with the formula above, it has delegation warning:
patch existing cds 2.png

 

ForAll(GalleryRejectedInspectionChecklist.AllItems, Patch('SMU_ Service Lines', LookUp('SMU_ Service Lines', cr807_key = LabelKeyRejectedInspection.Text),
{cr807_responds: RadioRespondsRejectectedInspection.Selected.Value,
cr807_respondtext: TextInputQuestionRejectedInspection.Text,
cr807_remarks: TextInputRemarksRejectedInspection.Text}));

Please Help,

 

Thanks.

Pytbyt

Super User
Super User

Re: Patch specific record CDS

Hi @PytByt 

Your formula 

Patch('SMU_Service Line', LookUp('SMU_Service Line', cr1e4_key = LabelKeyRejectedInspection.Text),
{cr1e4_responds: RadioRespondsRejectectedInspection.Selected.Value,
cr1e4_respondtext: TextInputQuestionRejectedInspection.Text,
cr1e4_remarks: TextInputRemarksRejectedInspection.Text});

References the labels in your gallery rather than the actual value of the item.  When I use Patch(), I always refer to the actual item to prevent disambiguation.  For example, 

Patch(datasource,
Lookup(datasource, ID = Gallery1.Selected.ID),
{Fieldname1: TextInputx.Value, Fieldname2: Dropdownx.Selected.Value, Fieldname3: Radiox.Selected.Value})

In your example, if you are using an icon inside of the gallery to submit the patch, you can use ThisItem instead of a Lookup() 

TechNerd
Level: Powered On

Re: Patch specific record CDS

Hi

I have the same issue, I have a gallery that I want to patch a value back into CDS from the powerapp and update a field in Dynamics 365. I have a Option Set in Dynamics with a Radio control in my canvas app. I want to change the radio1 control in the same gallery. 

 

 
mike528
Level: Powered On

Re: Patch specific record CDS

If you have the source of the gallery items connected to a CDS entity or entioty view, for the record reference, you can simply use Gallery1.Selected or ThisItem depending upon where you put the patch command.

 

For example, if you want to save the record using a button within the gallery item, you can use Patch(Entity, ThisItem, {Field: Value}). 

 

If you use a radio button with set the Items to Choices(Entity.Field), then in your patch command simply use {Field: Radio1.Selected.Value}.

 

Hope this helps.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (3,768)