Task List - Related Items Column

Copper Contributor

I have a document library and a task list in SharePoint. When a file is created on the document library, I need to create a task list item and set the value of 'related items' column to the file that was created (to link/relate them) so that when the task list item is opened or viewed, the user is redirected to the file on the document library (I think that's how it works).


I am able to create the task list item using SharePoint create item but the related items is not populated during this action because field is not visible on the action.

 

Now, I added another action - Send an HTTP request to SharePoint to update the 'related items' column. The action is successful after running the flow but when I checked the column, related items column is empty, it's supposed to display 1 related item and when opened should redirect to the document library.

 

Below are the screenshots.

 

Lym_Wale_4-1673137756106.pngLym_Wale_5-1673137863018.png

 

Additional information: I'm converting Nintex Workflow. The screenshot with 1 related item above was created using Nintex Workflow.


Any help is appreciated. Thanks in advanced.

2 Replies

Hiiiii@Lym_Wale,

 

Here is Ahmed, I'm a community visitor!

Let me try help you today:

 

 

To resolve the issue with the related items column not being populated in your task list, you can try the following steps:

 

  1. Make sure that the file created in the document library has a unique identifier, such as a file name or file ID, that can be used to relate it to the task list item.

  2. In the "Send an HTTP request to SharePoint" action, set the URI to the URL of the task list item that you want to update, and use the "PATCH" method. In the request body, include the following JSON:

{ "__metadata": { "type": "SP.Data.TasksListItem" }, "RelatedItemsId": { "results": [ "FILE_ID_OR_NAME" ] } }

Replace "FILE_ID_OR_NAME" with the unique identifier of the file in the document library.

  1. Save and run the flow again, and check the task list item to see if the related items column has been updated with the file from the document library.

If the above steps do not resolve the issue, you may want to check the permissions of the user who is running the flow to make sure that they have the necessary permissions to update the task list item. Additionally, you can try using the "Get item" action to retrieve the task list item before updating it, to verify that the item is being returned correctly.

 

If my solution was helpful, please mark this question as answered and consider giving it a thumbs up.

Your positive feedback motivates me to continue helping others.

Thank you for letting me be a part of your journey to finding a solution!

Ahmed

Hi @Lym_Wale 

To add elements to the default "Related Items" column in a default SharePoint task list you need to uses the following REST endpoint

_api/SP.RelatedItemManager.AddSingleLinkToUrl


You can use it like this in PowerAutomate

RelatedItems.png

POST _api/SP.RelatedItemManager.AddSingleLinkToUrl
Content-Type application/json;odata=verbose

{
    "SourceListName":"Tasks",
     "SourceItemID":1,
     "TargetItemUrl":"/sites/classic/Shared Documents/Document.pdf",
     "TryAddReverseLink":true
}




This call adds the file "/sites/classic/Shared Documents/Document.pdf" to the task with the ID 1 in the task list "Tasks" as a related item.

Best Regards,
Sven