cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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,CDSColumn2Smiley Very HappyatePicker1.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!

5 REPLIES 5
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: Powered On

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: Powered On

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

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

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

Users Online
Currently online: 58 members 3,539 guests
Please welcome our newest community members: