1

I have a SharePoint document library and I've created two custom workflow. Then i attached those workflows to a document library. What i'm trying to do is getting workflow status and URL with single REST API.

What I've tried is;

/_api/web/lists/getbytitle('E-Test')/items(37)?$select=DockApprove,DocSignature

DockApprove and DocSignature is my custom created workflows, and when i run this on Chrome browser, it returns;

<entry xml:base="http://SPTest/_api/" m:etag=""2""...........">
    <id>Web/Lists(guid'5ddb9547-0954-4ad5-bea8-792fb16e1fab')/Items(37)</id>
    <category term="SP.Data.ESig" scheme="......."/>
    <link rel="edit" href="Web/Lists(guid'5deb9547-0954-4ed5-bef8-792fb16e1fbb')/Items(37)"/>
    <title/>
    <updated>2023-07-24T11:58:41Z</updated>
    <author>
        <name/>
    </author>
    <content type="application/xml">
        <m:properties>
            <d:DockApprove m:type="Edm.Int32">20</d:DockApprove>
            <d:DocSignature m:type="Edm.Int32">5</d:DocSignature>
        </m:properties>
    </content>
</entry>

DockApprove returns 20 and DocSignature returns 5 which they are their status ID. I need to get full name like "Approved", "Declined" etc.

And i need to get an URL like http://SPTest/_layouts/15/WrkStat.aspx?List=5ddb9547-0954-4ad5-bea8-792fb16e1fab&WorkflowInstanceID=%7b..........%7d from the REST API.

For URL, I tried to add WorkflowInstanceID on URL next to Select, but WorkflowInstanceID always returns null. Since i have multiple workflow, i also tried to expand DockApprove and DocSignature, thinking maybe i'll get URL and Status, but i could't get any result.

So is it possible to get custom workflow's status and ID or URL with single or multiple rest API request? Then users can click the URL and easily can go and check the workflow if needed.

Thank you

Update: I found a solution for getting workflow status as a text;

/_api/Web/Lists(guid'......')/Items(37)/FieldValuesAsHtml?$select=DockApprove and the return is "Approved"

Now I'm trying to get WorkflowInstanceID or URL for each workflow that i attached to list.

Update: Main idea is creating an url like ..site/_layouts/15/WrkStat.aspx?List=[ListGuid]&WorkflowInstanceID=[WF_InstanceID] for navigating that workflow details. That's why i need WorkflowInstanceID

1 Answer 1

0

You can use following code

ExecuteOrDelayUntilScriptLoaded(getWorkflowStatus, "sp.js");  
var listTitle = 'Tutorial';  
var listItemId = 1;  
var workflowTitle = 'Approval';  

function getWorkflowStatus()  
{  
  var context = new SP.ClientContext.get_current();  
  var web = context.get_web();  
  var list = web.get_lists().getByTitle(listTitle);  
  var listItem = list.getItemById(listItemId);     
  context.load(listItem);  
  context.executeQueryAsync(  
     function() {  
       var workflowStatusField = listItem.get_parentList().get_fields().getByTitle(workflowTitle); //get workflow status field  
       var workflowStatusValue = listItem.get_item(workflowTitle); //get workflow status field value  
       console.log('Approval is completed');  
     },  
    function(sender,args){  
   console.log(args.get_message());  
     }  
  );  
}  
1
  • Thank you for help. How can i get a workflow instance id also? Main idea is when users clicks the url (workflow status), user can go to that workflow. ex: ..site/_layouts/15/WrkStat.aspx?List=[ListGuid]&WorkflowInstanceID=[WF_InstanceID]
    – Allen
    Jul 31, 2023 at 9:42

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.