How to retrieve workflow id by using jsom in SharePoint online?

This SharePoint JSOM tutorial explains, how to retrieve workflow id from a list using JavaScript object model code (jsom) in SharePoint online. Here we have a list in our SharePoint Online site and into that list, we have attached a few list workflows. By using, the below code we are going to retrieve the id of the workflow whose name is “Archiving”.

In this particular example, I have added the below code inside a script editor web part which I have added inside a web part page.

If you are new to JSOM SharePoint Online, you can read Working with JavaScript object model (jsom) in SharePoint 2013 or SharePoint Online.

<input type=”button” id=”btnSubmit” value=”Get Workflow ID” /><br/>

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<script>
$(function () {
bindButtonClick();
});
function bindButtonClick() {
$(“#btnSubmit”).on(“click”, function () {
getWorkflowId();
});
}

function getWorkflowId() {
SP.SOD.executeFunc(“sp.js”, “SP.ClientContext”, function () {
SP.SOD.registerSod(‘sp.workflowservices.js’, SP.Utilities.Utility.getLayoutsPageUrl(‘sp.workflowservices.js’));
SP.SOD.executeFunc(‘sp.workflowservices.js’, “SP.WorkflowServices.WorkflowServicesManager”, function () {
context = SP.ClientContext.get_current();
web = context.get_web();
workflowServicesManager = new SP.WorkflowServices.WorkflowServicesManager(context, web);

var subs = workflowServicesManager.getWorkflowSubscriptionService().enumerateSubscriptionsByList(‘4C384857-8AEF-484E-8163-FED3592E15A4’);

context.load(subs);
context.executeQueryAsync(function () {
var subEnumerator = subs.getEnumerator();
while (subEnumerator.moveNext()) {
var sub = subEnumerator.get_current();
if (sub.get_name() == ‘Archiving’) {
var templateId = ‘Workflow id: ‘+sub.get_id();
alert(templateId)
return;
}
}
},
function (sender, args) {

alert(args.get_message());
});
});
});
}
</script>

Once you Save the code and click on the button, it will display the workflow id inside an alert box like below:

How to retrieve workflow id by using jsom in SharePoint online

How to retrieve workflow id by using jsom in SharePoint online

You may like following SharePoint designer workflow tutorials:

Hope this will be helpful to retrieve workflow id by using jsom in SharePoint online Office 365.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

>