I have a flow through Power Automate and one of its functions is to modify metadata of a file stored in a Sharepoint library based on certain criteria. The metadata is stored in custom columns and the document may be located in a number of libraries, depending on its country.
At the moment, I read the country from the file, this I feed into the Switch control and for each case, I have Update File Properties action, which modifies the metadata. This works perfectly, however it feels very inelegant because for each newly supported country, I have to add a case into the Switch control and define the steps (and if I decide to implement a change, I will need to do so again for each case). I can input the library name dynamically as "DL_" & File.Country
, however in that case the action does not offer me the custom columns because it does not know which library it will access before run time.
Is there a way around this limitation that would allow me to remove the Switch/Case controls? The columns with metadata are the same in each of the document libraries (they are built from the same template), so I am essentially looking for a way to do it dynamically.
(moved here from Super User forum)
EDIT:
So some additional details here - this is the library (DL_LUX as opposed to DL_BEL etc. for other countries) and the columns I am updating with the document metadata.
I tried the REST API way but it is the first time I hear about it so I have actually no idea what I am doing (DL_LUX is hardcoded now for testing purposes).
EDIT 2: So I think I am getting the some slight idea about what I am trying to do... I managed to run a successful HTTP GET request to get the item data:
{
"d": {
"__metadata": {
"id": "9c56162b-dad7-4025-b3ba-21bb7d435932",
"uri": "https://evilcorp.sharepoint.com/sites/Library_Alexandria/_api/Web/Lists(guid'961afe78-ec3c-4279-b560-2297af7a4d3b')/Items(264)",
"etag": "\"2\"",
"type": "SP.Data.DL_x005f_LUXItem"
},
...
"Id": 264,
...
"Title": null,
"Category": "Onboarding",
"DocType": "Contract of Employment",
"Effective": "2020-11-01T07:00:00Z",
...
"ID": 264,
"Created": "2020-11-19T14:22:48Z",
"AuthorId": 10,
"Modified": "2020-11-19T14:22:49Z",
"EditorId": 10,
"OData__CopySource": null,
"CheckoutUserId": null,
"OData__UIVersionString": "2.0",
"GUID": "bfd8d847-1998-4d4a-b85e-fd205ba8e2d6"
}
}
With that mind, I changed the POST request to the below
But I am always getting a BadRequest error with description dependent on which headers I include or not, currently it is this
{
"status": 400,
"message": "Parsing JSON Light feeds or entries in requests without entity set is not supported. Pass in the entity set as a parameter to ODataMessageReader.CreateODataEntryReader or ODataMessageReader.CreateODataFeedReader method.\r\nclientRequestId: 59f5a1ad-af2d-4f59-b6dd-c829c8e89632\r\nserviceRequestId: 44328f9f-e026-b000-3d21-6fbd19e8d630",
"source": "https://evilcorp.sharepoint.com/sites/Library_Alexandria/_api/web/lists/getByTitle('DL_LUX')/items('266')",
"errors": [
"-1",
"Microsoft.Data.OData.ODataException"
]
}
EDIT 3: OK, so I think I almost have it. This code seems to do what I need
{'formValues':[
{'FieldName':'Category',
'FieldValue': 'Onboarding'},
{'FieldName':'DocType',
'FieldValue': 'Contract of Employment'},
{'FieldName':'Effective',
'FieldValue': '2020-11-01'}
]}
However, it does not seem to work with the Power Automate objects variables, only with literals. When I combine it with an object variable, it seems to evaluate properly, however in the list, the result is blank (except the date, which defaults to today).
EDIT 4: Finally resolved - the issue was the Effective date column which requires a specific date time format ("yyyy/MM/dd hh:mm:ss") while used just the date part or the standard UTC, which failed and tanked the whole CRUD request.