2

I want to stop a workflow when user clicks on the Cancel request button. To achieve this I am trying with the JSOM code. My code as follows

SP.SOD.executeOrDelayUntilScriptLoaded(function(){
    SP.SOD.executeOrDelayUntilScriptLoaded(function(){
        SP.SOD.executeOrDelayUntilScriptLoaded(function(){
                executeDeleteWorkflow();    
        },'SP.WorkflowServices.js');
    },'SP.Runtime.js');

},'SP.js');

var _subscriptions =null;
function executeDeleteWorkflow(){
    var listGuid = "702D453F-6D37-4133-9154-4C959E3A4F67";     
    var ctx = SP.ClientContext.get_current();
    var web = ctx.get_web();
    var sMgr =new SP.WorkflowServices.WorkflowServicesManager(ctx, web);
    var sservice = sMgr.getWorkflowSubscriptionService();
    var ssubs = sservice.enumerateSubscriptionsByList(listGuid);
    ctx.load(ssubs);
    ctx.executeQueryAsync(
       function(){
           var e = ssubs.getEnumerator();
             while(e.moveNext())
             {
               var c =  e.get_current();
               alert("Name :" + c.get_name() + " sID: " + c.get_id());
             };

       },
       function(){ 
            alert("error");
       });

}

When i try to execute this code it is showing error message as

Object doesn't support property or method 'get_context'

What is this meant by. This error message is coming from SP.WorkflowServices.js file Any solution for this?

0

Try replacing

 var sMgr =new SP.WorkflowServices.WorkflowServicesManager(ctx, web);

with

var sMgr = SP.WorkflowServices.WorkflowServicesManager.newObject(context,web);
  • Yeah I tried with that also. I think this is for sharepoint 2013 workflows. I created SP2010 workflow in office 365 – Mihir Oct 30 '14 at 14:28
0

This error probably occurs since one of SharePoint JS library has not been loaded.

In order to use SharePoint 2013 Workflow Services Client Side Object Model the following JSOM libraries should be loaded:

  • SP.js
  • SP.WorkflowServices.js

You could use, for example, SP.SOD.executeFunc (SharePoint JavaScript Library) or jQuery.getScript() (jQuery ibrary) to ensure that the specified libraries have been loaded.

Example

$.getScript(SP.Utilities.Utility.getLayoutsPageUrl('sp.js'), function () {    
        $.getScript(SP.Utilities.Utility.getLayoutsPageUrl('sp.workflowservices.js'), function () {
           getSubscriptions('<list guid>');
        });    
});        


function getSubscriptions(listGuid)
{
    var ctx = SP.ClientContext.get_current();
    var web = ctx.get_web();
    var wsm =new SP.WorkflowServices.WorkflowServicesManager(ctx, web);
    var subscriptions = wsm.getWorkflowSubscriptionService().enumerateSubscriptionsByList(listGuid);
    ctx.load(subscriptions);
    ctx.executeQueryAsync(
       function(){
          //...
       },
       function(sender,args){ 
           console.log(args.get_message());
       });
}
  • 1
    I am giving the SP.WorkflowServices.js file url as 'mysiteurl/_layouts/15/SP.WorkflowServices.js". I verified in the developer tools whether the worflowservices.js file is loaded or not. There it is showing the file properly. Please find the edited question. – Mihir Oct 30 '14 at 14:31
0

I encountered this issue myself where I verified that the SP.WorkflowServices.js file is loaded, but still encounter the "get_context()" error, making it seem like the object is not instantiated at all. I found that Vadim's suggested answer is the solution, however not complete, unless you've ensured that the SP.Utilities.Utility class is loaded first. The complete solution that eliminated issue for me is:

SP.SOD.executeFunc('sp.js', 'SP.Utilities.Utility.getLayoutsPageUrl', init); 

function init() {
$.getScript(SP.Utilities.Utility.getLayoutsPageUrl('sp.js'), function () {    
      $.getScript(SP.Utilities.Utility.getLayoutsPageUrl('sp.workflowservices.js'), function () {
           getSubscriptions('<list guid>');
        });    
});        
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.