0

I'm using some javascript code to retrieve the workflow definitions on my site:

var context = SP.ClientContext.get_current();
var web = _context.get_web();
var serviceManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
var deploymentService = serviceManager.getWorkflowDeploymentService();
var definitions = deploymentService.enumerateDefinitions();

context.load(definitions);

return context.executeQuery()
         .then(function(){
             console.log(definitions);
             var enumDefs = definitions.getEnumerator();

             while(enumDefs.moveNext()){
             ....
         });

BTW I've wrapped executeQueryAsync with jQuery Deferred so my JSOM code can resemble my REST code. Here is a John Liu's blog on how to do that.

This is working and I can clunkily iterate my way through the list. But I really, really dislike using the SP complex types and all their methods.

In the browser I see that a nice simple json array is being send back as the response. Is there anyway I can just get that?

Is there some way to easily change all the information that comes back into a json object?

6
  • Why is it clunky? How are you using this query?
    – Mike
    Nov 3, 2017 at 19:35
  • How is it not clunky? :) First I have to getEnumerator() then uses a while(enum.moveNext()) then for every property or piece of information I want I have hope they included a getter method for it and also know what it is called and of course for each different call it will be different types with different property names. Finally once I leave the complete/success handler the data is gone. With a json object I can just return the object from my asych call and iterate over all of the values. Unless there is something like that and I just don't know what it is?
    – Rothrock
    Nov 3, 2017 at 19:58
  • Just store it in a json object or array on load or onclick (however you are triggering the fetch), then you can rummage through it after page load.
    – Mike
    Nov 3, 2017 at 20:07
  • Yes that is my question. How do I do that? With my debug tools I see definitions item, but it is a complex object with methods and things that I don't need. If I try JSON.stringify(definitions) I get an Converting circular structure to JSON error. I think what I want is in enumDefs.get_current().$5_0.$H_0, but that doesn't seem like a stable way to work. Is there a simple and understandable way to convert it?
    – Rothrock
    Nov 3, 2017 at 20:34
  • something like var wfarray []; var enumDefs = definitions.getEnumerator(); while(enumDefs.moveNext()){ var currentwf = enumDefs.get_current(); wfarray.push(currentwf); } //do something with wfarray;
    – Mike
    Nov 3, 2017 at 20:37

1 Answer 1

1

You can use a next code to get simple objects

return context.executeQuery()
     .then(function(){
         return definitions.get_data().map(function(item) {
           return item.get_objectData().get_properties();
         });
     });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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