Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharePoint JavaScript API for Workflow throws an error

I am trying to access information about running workflows in a SharePoint list but I am running into problems with the workflow services JSOM library. I am using the workflow services just like every example I can find, see code below:

var context = SP.ClientContext.get_current();
var web = context.get_web();
var servicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
var instanceService = servicesManager.getWorkflowInstanceService();

While executing the code, the last line in the above snippet throws an exception

TypeError: this.get_context is not a function.

like image 607
Travis L Avatar asked Nov 29 '25 11:11

Travis L


1 Answers

Propbaly this error occurs since one of the specified files from SharePoint JavaScript library has not been loaded.

  • SP.js
  • SP.Runtime.js
  • SP.WorkflowServices.js

To ensure that the specified file(s) has been loaded you could consider the following approach:

SP.SOD.registerSod('SP.ClientContext', SP.Utilities.Utility.getLayoutsPageUrl('sp.js'));
SP.SOD.registerSod('SP.WorkflowServices.WorkflowServicesManager', SP.Utilities.Utility.getLayoutsPageUrl('SP.WorkflowServices.js'));
SP.SOD.loadMultiple(['SP.ClientContext', 'SP.WorkflowServices.WorkflowServicesManager'], function(){

    var ctx = SP.ClientContext.get_current();
    var workflowServicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx.get_web()); 
    var workflowSubscriptionService = workflowServicesManager.getWorkflowSubscriptionService();                
    //...    

});

SP.SOD.loadMultiple function is intended for loading on demand scripts which in turn is a part of SharePoint JavaScript Library. Alternatively you could utilize jQuery.getScript() from jQuery library.

like image 156
Vadim Gremyachev Avatar answered Dec 01 '25 01:12

Vadim Gremyachev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!