Uncaught TypeError: Cannot read property 'WorkflowServicesManager' of undefined from CSOM (NAPA)

SharePoint Online 2013.  Trying to access SP.WorkflowServices.WorkflowServicesManager  from NAPA (CSOM).  Getting error :  Cannot read property 'WorkflowServicesManager' of undefined

NAPA App is shared here :  http://aka.ms/V8v2di

We've been able to access the class with PowerShell with no problem.

Here's the code in question:

(function () {

// Getting client context and loading the current web
var context = SP.ClientContext.get_current();
var web = context.get_web();
context.load(web);

// Workflow Services API entry point - WorkflowServiceManager object
var servicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
context.load(servicesManager);

var workflowDefinitions = servicesManager.getWorkflowDeploymentService().enumerateDefinitions(false);
context.load(workflowDefinitions);

context.executeQueryAsync(function (sender, args) {

    // enumerateDefinition returns ClientCollection object
    var definitionsEnum = workflowDefinitions.getEnumerator();

    var empty = true;

    console.log('Site ' + web.get_url() + ':');

    // Going through the definitions
    while (definitionsEnum.moveNext()) {

        var def = definitionsEnum.get_current();

        // Displaying information about this definition - DisplayName and Id
        console.log(def.get_displayName() + " (id: " + def.get_id() + ")");

        empty = false;

    }



  • Edited by o365spo Monday, August 17, 2015 1:05 PM
August 17th, 2015 12:15pm

Hi,

According to the error message, please check the whether you have loaded the workflow services library sp.workflowservices.js before executing your code.

Here is a demo about how to work with workflow service using JavaScript for your reference:

http://www.codeproject.com/Articles/782859/Working-with-Workflow-Service-in-JavaScript-JSOM-i

Thanks 

Patrick Liang

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 2:07am

Hi, thanks.

But we already have reference in Default.aspx web app page -

<script type="text/javascript" src="/_layouts/15/sp.workflowservices.js"></script>.

Also I've checked sp.workflowservices.js script and it looks ok (already included definitions for methods requested in my script). So problem somewhere in NAPA or O365.

August 19th, 2015 11:14am

Hi,

This is the screenshot of your default.aspx:

Seems that the App.js is loaded before the sp.workflowservices.js, this might be the cause of Cannot read property 'WorkflowServicesManager' of undefined.

Please reference the JavaScript libraries as below and make another test:

Thanks                 

Patrick Liang

Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 9:42pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics