cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

How to update a Gallery collection row when using a Custom Connector

Hi.

This is a followup from this post regarding using a PATCH request in a custom connector:

https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/Custom-Planner-Connector-to-update-... 

In my PowerApp using the standard Planner connector I can update the Task Title of the current record in the Gallery eg

 

onChange = Planner.UpdateTaskV2(id,{title:TaskTitle.Text})

 

 ie in the onChange event handler of the gallery template component called "TaskTitle", call the Planner connector method UpdateTaskV2(id,{title:TaskTitle.Text}) and yes, the Task Title updates in Planner.

 

So far so good. Now, I am using a custom connector in order to do more than the standard Planner connector allows (i.e. update the bucketId to move a task from one bucket to another, as per the link mentioned above). I have created an action on my custom connector called UpdateTask() which does a PATCH request and that works. However, there is a big difference between the standard UpdateTask() and my custom UpdateTask() which relates to the '@odata.etag' property of the gallery record.

In Graph, in order to update a record you need to send the current value of '@odata.etag' in your PATCH request via the If-Match header. Then, when the request returns, as long as you also passed the header

Prefer return=representation

you will get back the updated record including the new '@odata.etag' so you can then do another update of that same record. See the link above for the details on that. The custom Planner connector call looks like this:

onChange = PlannerCustomConnector.UpdateTask(id,'@odata.etag',{title: TaskTitle.Text})

i.e. the same as the standard Planner connector except you need to pass the current etag.

In the standard Planner connector you do not need to handle '@odata.etag' at all. You can make successive calls via

onChange = Planner.UpdateTaskV2(id,{title:TaskTitle.Text})​

So, for the custom Planner connector to work for successive calls to UpdateTask() you need to update the gallery collection row with the new etag after each call to UpdateTask(). Since the custom connector returns the whole new Task record I thought I could update the gallery collection row (which is table variable varServerTasks) using:

Update(varServerTasks,ThisItem, PlannerCustomConnector.UpdateTask(id,'@odata.etag',{title: TaskTitle.Text}) )
or
Update(varServerTasks,ThisItem, PlannerCustomConnector.UpdateTask(id,'@odata.etag',{title: TaskTitle.Text}).value )
or
Update(varServerTasks,ThisItem, First(PlannerCustomConnector.UpdateTask(id,'@odata.etag',{title: TaskTitle.Text}).value) )

However the Update() function throws a syntax error in all those cases.

My workaround is to use Patch() on the onChange function for the item field instead:

ClearCollect(
    varUpdatedTask,
    PlannerCustomConnector.UpdateTask(
        id,
        '@odata.etag',
        {title: TaskTitle.Text}
    )
);
Patch(
    varServerTasks,
    ThisItem,
    {
        '@odata.etag': First(varUpdatedTask).'@odata.etag',
        title: First(varUpdatedTask).title
    }
)

 i.e. when the task title is changed, capture the returned updated record from the PlannerCustomConnector.UpdateTask() action to varUpdatedTask then Patch the varServerTasks collection record with the changed columns.

It is good that this workaround works. However, it is a lot of code and I have a few fields that can be updated directly from the gallery item (title, bucketId, dueDateTime, etc) which means I need to repeat the block above on every one of those field's onChange function!

Is there a better way to do this?

Thanks,

Murray

3 REPLIES 3
Highlighted
Community Support
Community Support

Hi @murrah ,

 

Could you share the error information?

The issue is probably due to that the column names don't match. If you are using Update function ,the column name of record generated by PlannerCustomConnector.UpdateTask function must match the collection column name. By the way, the update function is to replace an entire record, the columns that are not updated will be blank. Could you check if all column names are matched?

The workaround you are using is great, patching specific column can well avoid the above possible problems.

If you don't want to apply the code to all control, you could add a Modify button to patch all field intensively.

Sik

Highlighted

Thanks Sik.

What I am doing is this:

First, I collect the tasks for a plan from the server into a collection. The reason is so I can then filter, sort and search my local collection in a gallery without needing round trips to the server each time.

 

ClearCollect(
    varServerTasks,
    PlannerCustomConnector.ListTasks("plan id goes here").value
);

 

The collection is used in a Gallery:

 

Items = varServerTasks

 

In the gallery item, I am allowing the user to update fields like title, bucketId, dueDateTime, etc directly on the Gallery item, ie not opening an edit form. It is for that reason that I want to emulate the standard Planner connector whereby one can do the following for just one field. ie if the task title is edited:

 

onChange = Planner.UpdateTaskV2(id,{title:TaskTitle.Text})

 

What I am wanting is the custom connector equivalent of that. The custom connector UpdateTask() action returns the complete updated record which I wanted to use to update the gallery item. Something like:

 

Update(varServerTasks,ThisItem, PlannerCustomConnector.UpdateTask(id,'@odata.etag',{title: TaskTitle.Text}))

 

When I mouse over the "UpdateTask" part of that function the error I get is: "Incompatible type. The item you're trying to put into a collection has a type that's not compatible with the collection."

BUT... if I use this function to capture the returned value of the UpdateTask() action, that syntax works fine.

 

ClearCollect(
    varUpdatedTask,
    PlannerCustomConnector.UpdateTask(
        id,
        '@odata.etag',
        {title: TaskTitle.Text}
    )
);

 

Which leads me to your suggestion that the columns in ThisItem are not the same as those returned from the UpdateTask() action. When I compare the columns, I see that the response signature from Graph

 

https: //graph.microsoft.com/v1.0/planner/tasks/{taskid}

 

is not the same as the items from

 

https: //graph.microsoft.com/v1.0/planner/plans/{planid}/tasks

 

in that "@odata.context" is in the UpdateTask() response but is not present in "ThisItem" via the ListTasks() action. I tried removing that "@odata.context" from the custom connector definition but that seems to have broken my connector.

Sik, I appreciate your help. However, I have abandoned my whole Planner project for the reasons in this post. Accordingly, I cannot spend any more time trying to make this work. Despite abandoning the project I was interested to try to resolve this issue so others might be able to get it to work. However, I need to direct my time now to finding an alternative to using Planner. Sorry, I can't be of more help here. Feel free to close this out.

Best wishes, Murray

Highlighted

OK, just close it out

Sik

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (8,838)