cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Frequent Visitor

Re: Patch specific record CDS

Correction: 

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

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

Highlighted
Post Prodigy
Post Prodigy

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

Highlighted
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

Highlighted
Post Prodigy
Post Prodigy

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

Highlighted
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() 

Highlighted
Frequent Visitor

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. 

 

 
Highlighted
Resolver I
Resolver I

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
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (10,750)