none
SharePoint Designer 2013 call HTTP web service: DELETE workflow not working RRS feed

  • Question

  • I am trying to create a SharePoint 2013 workflow through SharePoint Designer that will delete a Calendar item based on 2 parameters (Title and Category) once a new item is created where Category='Returned'.  I've started the workflow with a conditional statement of: If Current Item:Category equals Returned.  

    Then I'm using the Call HTTP web service action and I have my dictionary built with 2 variables (accept = application/json;odata=verbose and content-type = application/json;odata=verbose) and the URL lookup listed as the string: 
    [%Workflow Context:Current Site URL%]_api/web/lists/getbytitle('[%Workflow Context:List Name%]')items?$select=Title('[%Current Item:Title%]'),Category('Due Back')  The HTTP method is set to DELETE.  

    I think my coding in the lookup string is wrong somehow, but I'm not a coder, so I'm not sure where I'm going wrong.  I am very new to SharePoint Designer so any help is appreciated.  Thanks.
    Thursday, June 25, 2020 3:24 PM

All replies

  • Hi KMilner,

    Here is a sample request to delete ListItem in a specific list using ajax:

    $.ajax({
        url: "https://Tenant.sharepoint.com/sites/test/_api/web/lists/getbyTitle('ListTitle')/items(5)",
        type: 'POST',
        contentType: 'application/json;odata=verbose',
        headers: {
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "IF-MATCH": "*",
            "X-HTTP-Method": "DELETE"
        },
        success: function (data) {
            console.log(data);
        },
        error: function (error) {
            console.log(error);
        }
    })

    In the url we need to specify the ItemId in items(), in the ajax demo above, the ItemId is 5.

    And back to workflow, the header dictionary should as below:

    And add condition check for Category and Title in workflow step directly, this is the complete workflow steps and conditions:

    In additional, please specify the request header for Rest API call by right click the action:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, June 26, 2020 7:01 AM
  • Thank you for the solution.  I have some follow-up questions, though. 

    First, (and this will sound dumb) where does that first set of coding go?

    Second, my calendar essentially tracks a library type program.  A "book" is lent out and must be returned by a certain date, but if it is returned before the due date, then I no longer want the due date calendar item to be there anymore (hence the deletion).  The problem this results in is that the "Current Item" in the workflow would not be the same item that I want deleted.  The "Current Item" would be the item created when the book is returned prior to the due date.  

    Third, this would be a recurring workflow, I don't want all my due back dates to be deleted, just the one's that have a returned date created with a matching title.

    How can I address these issues?

    Thank you again for your help!

    Monday, June 29, 2020 12:12 PM
  • Hello KMillner,

    First:

    This is a sample Ajax Rest Request to delete the Calendar list item, it display the correct header and this is a reference for you to use in Workflow.

    Second and Third:

    If you want to delete a item just for  the one which have return date and match some Title value, you can add If conditional check in the workflow like the suggestion above and if meerts the condition, then call the Rest to delete item.

    Here is a sample to check if a date field is blank in workflow for your reference:

    Check if a date field is blank in a SharePoint Designer workflow

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, June 30, 2020 3:15 AM