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-the-bucketId-on-a-task-how-to/m-p/427680#M126603
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