1

I need to get the Workflow Id with java script after editing a Workflow Task. What I have this far is only a script that gets the Task Id when the EditForm is opened:

$(document).ready(function () {

JSRequest.EnsureSetup();
var xId = JSRequest.QueryString["ID"];
//need to get the Workflow Id here

Any suggestions? All help would be appreciated!

Edit: tried to look for the Workflow Id with REST and Postman on the Workflow Task List but also there I can't find the Workflow Id Does this mean it's impossible?

3

I guess you mean Workflow Instance Id, right? It depends on SharePoint version.

SharePoint 2010 or SharePoint 2013 (Platform Type: SharePoint 2010 Workflow)

Workflow Instance Id is stored in field WorkflowInstanceID (Type: SP.Guid)

Example:

var listId = _spPageContextInfo.pageListId;
var itemId = parseInt(GetUrlKeyValue('ID'));

getListItem( listId,itemId,
   function(item){
       var workflowInstanceId = item.get_fieldValues()['WorkflowInstanceID'].toString();
       console.log(workflowInstanceId);
   },
   function(sendera,args){
       console.log(args.get_message());
   });

SharePoint 2013 (Platform Type: SharePoint 2013 Workflow)

Workflow Instance Id is stored in field WF4InstanceId

Example

var listId = _spPageContextInfo.pageListId;
var itemId = parseInt(GetUrlKeyValue('ID'));

getListItem( listId,itemId,
   function(item){
       var workflowInstanceId = item.get_fieldValues()['WF4InstanceId'];
       console.log(workflowInstanceId);
   },
   function(sendera,args){
       console.log(args.get_message());
   });

getListItem function

function getListItem(listId,itemId,success,error)
{
   var ctx = SP.ClientContext.get_current();
   var web = ctx.get_web();
   var list = web.get_lists().getById(listId);
   var item = list.getItemById(itemId);
   ctx.load(item);

   ctx.executeQueryAsync(
      function() {
          success(item); 
      },
      error);
}
  • 1
    exactly, meant the Workflow Instance Id :). And your code worked perfectly, thanks!!!!!! – tomvanderhoek Mar 20 '15 at 22:43

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.