Using GetWorkflowDataForItem

Nov 8, 2011 at 7:46 PM

My intention is to pull the Approving user for a list item to be displayed in DispForm.aspx. I feel like I have all of the information I need, except what's returned when GetWorkflowDataForItem is successful. Here's my code:

 $().SPServices({
  operation: "GetWorkflowDataForItem",
  async: false,
  item: "https://domain/site/Lists/Listname/" + itemID + "_.000",
  completefunc: function (xData, Status) {

  }
 });

itemID is defined earlier in the code and is confirmed to work properly - it's using jQuery.url to pull the ID from the URL. There's another operation in the code which uses it successfully.

What I'd ideally like to do is take everything that's returned from pulling the information and display it on the page so I can see what I'm working with (this is why "completefunc" is empty). Unfortunately I've not come up with any easy ways to see this in the same fashion as owssvr.dll to display List XML.

Coordinator
Nov 8, 2011 at 7:49 PM

I have a couple of tricks that I use, one of which might for for you:

  • Alert xData.responseText
  • Add a textarea to the DOM populated with xData.response.Text
  • Use Firebug and look at the traffic on the Net tab

Thos are the main ones, though there are others. Let me know what works for you!

M.

Nov 8, 2011 at 7:57 PM
Edited Nov 8, 2011 at 7:57 PM

Brilliant, thank you Marc. Unfortunately this method doesn't contain the information I need. It was kind of a shot in the dark, so I'll explain what I'm trying to do. For items that have been approved, I'd like to pull the Approving Authority from the Workflow Status of the item, then display it on the DispForm.aspx. It was easy enough to pull the status itself using GetListItems, but unfortunately there's no column for Approving Authority. Would this require GetWorkflowTaskData? I sure hope not, unless the taskId parameter is optional...

Nov 8, 2011 at 8:07 PM

Just tried to run GetWorkflowTaskData on a specific item and receiving an error. Here's the code:

 $().SPServices({
  operation: "GetWorkflowTaskData",
  async: false,
  item: "https://domain/sites/Lists/Listname/" + itemID + "_.000",
  listId: "{F43E2197-BD09-4AEA-AC3F-E515B8CE22D0}",
  taskId: "{CF0B20D0-8240-4384-A47F-451D2AA7DE03}",
  completefunc: function (xData, Status) {
   alert (xData.responseText);
  }
 });

And this is the error:

<!--?xml version="1.0" encoding="utf-8"?-->soap:ClientServer was unable to read request. ---> There is an error in XML document (1, 456). ---> Input string was not in a correct format.
I've verified each GUID.

Nov 9, 2011 at 3:10 PM

All right, the taskId is NOT the GUID, but rather the simple unique ID of the item in the task list. Changing that fixed it and I got the information I need.

There's still a problem - I need to be able to automatically pull the ID for the workflow task item using any resources available to me on the DispForm.aspx page for the item the workflow's being run on.

Nov 9, 2011 at 4:17 PM

Totally threw out what I had and went to a much simpler process. See my successful code below:

 $().SPServices({
  operation: "GetListItems",
  async: false,
  listName: taskListGUID,
  viewName: taskViewGUID,
  CAMLQuery: "<Query><Where><Contains><FieldRef Name='WorkflowLink' /><Value Type='Text'>ID=" + itemID + "</Value></Contains></Where></Query>",
  completefunc: function (xData, Status) {
   $(xData.responseXML).find("[nodeName='z:row']").each(function() {
    var approver = $(this).attr("ows_WorkflowOutcome");
	if (approver == undefined) {
	 $("#FieldApproval").append("Pending");
	} else {
         $("#FieldApproval").append(approver);
	}
   });
  }
 });

Yep, back to GetListItems. Much easier this way, and it works.

Feb 27, 2014 at 9:17 AM
CMK! the last solution will only give you the outcome of the current task (not the current Workflow)