2

I need to get the workflow or task ID for a list workflow based on the workflow name.

I am trying to follow the example here: Java script: how to get Workflow Id from Workflow Task Form

but it does not seem to be working for me.

   var ctx = SP.ClientContext.get_current();
   var web = ctx.get_web();
   listCollection = web.get_lists();
   list = listCollection.getByTitle(m_listName);
   var item = list.getItemById(m_itemID,'Include(WorkflowInstanceID)');
   ctx.load(item);

   ctx.executeQueryAsync(
            Function.createDelegate(window, function(sender, args) {  
                    var tasks = item.get_item("WorkflowInstanceID");

            }), 
            Function.createDelegate(window, function(sender, args)                {          
                var err = 'Request failed ' + args.get_message() + '\n' +      args.get_stackTrace();
                alert(err);

            })
    );

item.get_item("WorkflowInstanceID") successfully called but null is returned when WorkflowInstanceID is specified as a parameter.

Since I am using SharePoint 2013, I also tried using WF4InstanceId but the error "The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested." occurs.

Any way to get the task/ workflow ID based off of its name?

0

var clientContext = SP.ClientContext.get_current();
var website = clientContext.get_web();

var list = website.get_lists().getById(_spPageContextInfo.listId);
var itemId = GetUrlKeyValue('ID');
var item = list.getItemById(itemId);

// The task list has a hidden field "WF4InstanceId" which keeps tracks of the associated workflow id    
clientContext.load(item, ['Id', 'Title', 'WF4InstanceId']);
clientContext.executeQueryAsync(
    function (sender, args) {
        var properties = item.get_fieldValues();
        var WF4InstanceId = properties.WF4InstanceId;
        alert(WF4InstanceId);       
    },
    function (sender, args) {
        alert('Load task properties. ' + args.get_message());
});

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.