Vienna Power Apps and Power Automate User Group

Please login or click SIGN UP FOR FREE to create your PowerPlatformUG account to join this user group.

Patch Images from Collection to CDS Entity

  • 1.  Patch Images from Collection to CDS Entity

    Posted Sep 24, 2020 03:59 AM

    I want to share an article from my colleague Nils Eibenstein...this one is really helpfull

    deriving documentation from errors in PowerApps (dead memes included, tl;dr at bottom)

    It was a warm and sunny day, no clouds in the sky and non-migratory birds were complaining about the amount of cats in the backyard, while I was stuck inside trying to figure out how to patch pictures from a collection in PowerApps to an CDS Entity.
    Searching the world wide web's vast volumes of vetted wisdom turned up no results, at least none that were entirely satisfying.
    "Add a form to your app, add the picture there and then submit the form" or "Upload the picture as an attachment to an existing entity" were the workarounds postet there. None really fit my needs.

    The situation was as follows:
    My customer wanted an app to take pictures with, one or more, of installations, buildings and so on. Additionally those images needed to be enriched with metadata, such as which building, which part of the installation... you get the drift.
    The approach in using a form and using EditForm.Updates within a patch statement works well, but what to do when there is more than one picture?
    The idea of adding the pictures as attachment to an entity might work as well, but you cannot add significant metadata to that attachment, since it's bound to be attached to one entry within the entity. Which lead to me ruling out this option as well.
    Luckily Microsoft pointed me in the right direction by giving me an error message, when I was trying to patch a base64 string to the image object field in my entity.

    My first step on the gravelroad to the solution

    So obviously CDS image fields are records and it is not sufficient to just drop in a base64 string. Duly noted.
    But how is that record meant to be strucured? Which fields are needed? 

    Good thing was, that PowerApps provides at least a bit of a hint on which fields are needed, once you put a record  in your record.

    So the CDS demanded some field in that image record named "Full" with the type "Image"

    Great, I could deal with that. Since I already had a value holding the image from my camera control in my collection, I just used that. And lo and behold:
    It was not enough.

    Funny enough it accepted the direct input from the Camera Control and told me at the same time which second column had to be part of the record:

    Great, so now all I did was add the Camera.Photo to the Value column in the image record and it worked!

    and the funny thing is: you can get away with using either *.Photo or *.Camera for both columns:

    Now the only thing left was how to patch that collection. It turned out, that even though the entity didn't accept the input via lookup, it did accept the values when put in a ForAll statement:


    Add a record to within your patch statement containing the columns: Full and Value. Put an image value ,either directly from the camera input or a collection in each one, but don't use lookups and you are good to go.

                    img_Object: {
                        Full: picObj,
                        Value: Pic

    Harald Nagel
    Principal Consultant
    Arineo GmbH