0
votes

All of my workflows for a site have the ability to log data in the Workflow History list on my site. This is controlled at run-time with a parameter in list based on the workflow Name. I would like to be able to run a workflow on this setup table that will delete all records in the History list. My understanding is I can do this via REST call in SharePoint Designer workflow.

I have attempted many times to configure the REST Post command in Designer and I am never able to get this to work. I've searched over and over for a solution and not able to find such a solution.

I first tried deleting all that had the Workflow Association ID equal to the Workflow Name, but could not get that to work. Then I thought I would try selection each value using REST and then deleting that value using REST by the ID I received from the GET.

This is my delete (POST).

[%Workflow Context:Current Site URL%]/_api/lists/GetByTitle('Workflow History')/GetItemObject('[%Variable: HistoryID%]')

I also tried the DeleteListItem

[%Workflow Context:Current Site URL%]/_api/lists/GetByTitle('Workflow History')/DeleteListItem('[%Variable: HistoryID%]')

I want the user to be able to run this on any workflow from the setupWorkflow list I have. The workflow should delete all history for the current workflow.

1

1 Answers

0
votes

We can get the list items in Workflow History list base on the WorkflowInstance, in designer workflow, we can get the Instance ID from the Workflow Context.

/_api/web/lists/getbytitle('Workflow%20History')/items?$filter=WorkflowInstance eq 'b87b131e-ce22-43f5-85be-ec81d1045bc7'

Then delete list item using REST API below.

/_api/web/lists/getbytitle('Workflow%20History')/GetItemById(ID)

The following articles for your reference.

Using HTTP Call/ Rest API from SharePoint Designer workflow to create list

workflow to delete list item on subsite( Sharepoint designer call http web service )