Wednesday, April 6, 2016

Get Workflow Guid in Javascript using OData query

I find that using workflow id might be problematic across deployment, so I wrote a function to retrieve workflow’s guid given the workflow’s name. However, please take some care in assigning workflow name to avoid pain.

function call()
{
     
alert("Tets");
var name="Create Phone Call Via Js";
alert(name);
var wf=getWorkflowId(name);
alert(wf);

 }

function getWorkflowId(workflowName) {
var aa=workflowName;
var entityId = Xrm.Page.data.entity.getId();
alert(entityId);
alert(workflowName);

var serverUrl = Xrm.Page.context.getClientUrl();
alert(serverUrl);

var odataSelect = serverUrl + "/xrmservices/2011/OrganizationData.svc/WorkflowSet?$select=WorkflowId&$filter=StateCode/Value eq 1 and ParentWorkflowId/Id eq null and Name eq 'Create Phone Call Via Js'";

alert(odataSelect);

    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("GET", odataSelect, false);
    xmlHttp.send();

    if (xmlHttp.status == 200) {
        var result = xmlHttp.responseText;

        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.loadXML(result);
         
        return xmlDoc.getElementsByTagName("d:WorkflowId")[0].childNodes[0].nodeValue;
    }
}

Hope it Help!!

1 comment:

  1. Excellent post, thank you. You saved me a good few hours of work.

    ReplyDelete

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...