0

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. enter image description here

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). enter image description here

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

enter image description here

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).

enter image description here enter image description here enter image description here

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.

1 Answer 1

1

Per my knowledge, for now we only have triggers on document library level. Just like your trial, dynamic name will not help to get the custom column. One approach will be using Rest API to directly update the required field value based on the file country. You may need to compose the http request body with a dynamic country variable to select the proper library.

https://www.codesharepoint.com/sharepoint-tutorial/microsoft-flow-example-crud-operation-on-sharepoint-list

As I am not very clear about your final goal, please correct me if I get anything wrong.

Update from Eleshar's great work.

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. enter image description
here

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). enter image description here

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

enter image description here

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).

enter image description here enter image description
here enter image description here

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.

3
  • Thanks, this seems to point to the right direction. I have updated the question with additional details.
    – Eleshar
    Commented Nov 19, 2020 at 14:49
  • Jerry_MSFT: So I found the solution finally with the help of this reply and the quest for that solution is painstakingly recorded in my question via edits. You can update the answer, so I can accept it as correct.
    – Eleshar
    Commented Nov 20, 2020 at 10:30
  • @Eleshar, Good Job and thanks for your update and sharing. I will update the reply in no time and you can accept it to notify other community members.
    – Jerry_MSFT
    Commented Nov 23, 2020 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.