cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Kudo Collector
Kudo Collector

patch multiple records which include lookup field

Hi,

i have an entity on CDS called 'DailyPlans', which have the following fields:

1. PlanDate

2.Doctors_ (lookup field to entity Doctors)

3.Brands_ (lookup field to entity Brands)

 

so normally the app user will be able to add records to this entity using the regular (editform) which is fine. but after a while the user have to repeat all records from certain date to another.

e.g.: 

PlanDate            Doctors_           Brands_

3 Jun 2017         Dr. John          Piax

3 Jun 2017         Dr. Adam        Gestophil

 

now i want to "copy" these two record as new records on another date (e.g.:19 Jun)so the result would be like this:

 

PlanDate                      Doctors_                    Brands_

5 Jun 2017                   Dr. John                     Piax

5 Jun 2017                   Dr. Adam                   Gestophil

19 Jun 2017                 Dr. John                     Piax

19 Jun 2017                 Dr. Adam                   Gestophil

 

what i did so far is the following

  1. inserted two datepickers (date to copyand date to paste)
  2. the first datepicker OnChange property to collect the records of the date to copy
    ClearCollect(PlansToCopy, Filter('Daily Plans',PlanDate=CopyDatePicker.SelectedDate))
  3. created a gallery ans set its items property to the collection (PLansToCopy)
  4. insert a button and here i tried several fomulas without getting my needed result, when i used the below formula i only succeeded to copy one item (selected) from the gallery
    Patch('Daily Plans', Defaults('Daily Plans'), {Doctors_: TemplateGalleryList1.Selected.Doctors_, Brands_: TemplateGalleryList1.Selected.Brands_, PlanDate: PasteDatePicker.SelectedDate})
    but when i try try the use the (ForAll) i tried it in several places with different arguments with no use

Kindly advise.

Regards,

Mohammad Alkhawaja

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: patch multiple records which include lookup field

Hi @mokhawaja,

 

I think the issue here should be parameter used in the forall function.

Things we should notice first is Lookup type fields is in Record type.

As the collection would save the fields with the same name of the data source, here we could take use of the renamecolumns to mark the fields under collection.

So the formula which I think should work when using the Forall function should be the following:

ForAll(
   RenameColumns(
      RenameColumns(
               RenameColumns(PlansToCopy,"Doctors_","Doctors1"),
                   "Brands_","Brands1"),
                  "PlanDate","PlanDate1"),
   Patch("Daily Plans",
         Defaults("Daily Plans"),
         {Doctors_: Doctors1,Brands_:Brands1,PlanDate: PlanDate1}
        )
  )

Check to see if this would make it work.

Regards,

Michael

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

View solution in original post

3 REPLIES 3
Highlighted
Community Support
Community Support

Re: patch multiple records which include lookup field

Hi @mokhawaja,

 

I think the issue here should be parameter used in the forall function.

Things we should notice first is Lookup type fields is in Record type.

As the collection would save the fields with the same name of the data source, here we could take use of the renamecolumns to mark the fields under collection.

So the formula which I think should work when using the Forall function should be the following:

ForAll(
   RenameColumns(
      RenameColumns(
               RenameColumns(PlansToCopy,"Doctors_","Doctors1"),
                   "Brands_","Brands1"),
                  "PlanDate","PlanDate1"),
   Patch("Daily Plans",
         Defaults("Daily Plans"),
         {Doctors_: Doctors1,Brands_:Brands1,PlanDate: PlanDate1}
        )
  )

Check to see if this would make it work.

Regards,

Michael

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

View solution in original post

Highlighted
Kudo Collector
Kudo Collector

Re: patch multiple records which include lookup field

Hi @v-micsh-msft,

That works!!! although it needed some modifications, as i need to patch the date from the "PasteDatePicker", but there still appears an error with red line and the error says:

 

(The requested operation is invalid. Server Response: Date field is not formatted correctly)

 

Screenshot (28).png

 

 

 

kindly advise,

Regards,

Mohammad

Highlighted
Kudo Collector
Kudo Collector

Re: patch multiple records which include lookup field


@mokhawaja wrote:

Hi @v-micsh-msft,

That works!!! although it needed some modifications, as i need to patch the date from the "PasteDatePicker", but there still appears an error with red line and the error says:

 

(The requested operation is invalid. Server Response: Date field is not formatted correctly)

 

Screenshot (28).png

 

 

 

kindly advise,

Regards,

Mohammad



UPDATE...

 

I deleted the button and datepicker and re-inserted them again with the formula that worked and the error is gone!... now it works perfectly!!

 

 

Big Thanks!

 

Mohammad

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (9,933)