Search code examples
dynamics-crmetlmicrosoft-dynamicsdynamic-sql

Dynamics 365 API deactivate processes


I would like to automatically deactivate and activate processes on Dynamics CRM so I can upload data in between. Processes include updating information and setting one field to be another when it is inputted by user.

Is it possible to do this through the API? The documentation I saw online was mainly about querying from CRM

Reading documentation, looking on forums


Solution

  • use PATCH operation

    workflows table holds your Dynamics 365 workflows and actions and you need to find GUID of your particualr process

    https://abc.crm.dynamics.com//api/data/v9.2/workflows(c92dca98-8a13-44b9-bd13-02da90c8a38d)
    

    body as below

    {
        "statecode": 1,//state
        "statuscode": 2 // status
    }
    

    just tested this on Postman.

    below jquery code snippet

    var record = {};
    record.statecode = 1; // State
    record.statuscode = 2; // Status
    
    $.ajax({
        type: "PATCH",
        url: Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.2/workflows(c92dca98-8a13-44b9-bd13-02da90c8a38d)",
        async: true,
        headers: {
            "OData-MaxVersion": "4.0",
            "OData-Version": "4.0",
            "Content-Type": "application/json; charset=utf-8",
            "Accept": "application/json",
            "Prefer": "odata.include-annotations=*"
        },
        data: JSON.stringify(record),
        success: function (data, textStatus, xhr) {
            console.log("Record updated");
        },
        error: function (xhr, textStatus, errorThrown) {
            console.log(xhr);
        }
    });