cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to retrieve context of multiple instances in 1 Page Variable of SAP Build app

ajay_sharma10
Participant
0 Kudos
251

Issue:

I need to save the entire context of multiple instances in a single Page Variable, but I'm unsure how to implement a loop in the SAP Build app.

Scenario:

I have two Data Variables for the Workflow API: sapWorkflow and WorkflowInstance. The sapWorkflow variable fetches all "InProgress" workflows, while WorkflowInstance retrieves the context of a specific workflow selected by the user on the selection screen (fetched from sapWorkflow).

The filter conditions at the top of the page contain attributes that exist at the context level (i.e., the WorkflowInstance level). Therefore, I need to store the context of all fetched InProgress workflows into a single Page Variable to apply filters. 

Could you please suggest how to retrieve Context of multiple instance in 1 page variable

Accepted Solutions (0)

Answers (1)

Answers (1)

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

As far as I know there is no flow function to retrieve contexts and there is no API to retrieve all contexts from a subset of process instances.

So you can create a logic flow like this:

Dan_Wroblewski_0-1738526081652.png

FIrst, I create an integration to the destination you had to create for all the trigger/process flow functions.

Dan_Wroblewski_1-1738526170151.png

Then you create the above logic flow:

  1. I created a second page variable (loop variable) to hold all the instances, and copied all the info I retrieved into it.
  2. I used the new HTTP Destination Request flow function:
    • Set the destination to the one we added above.
    • Method GET
    • Path is a formula like this: "/public/workflow/rest/v1/workflow-instances/" + pageVars.PurchaseOrderInstancesLoop[0].id + "/context"
  3. I created a simple list of objects page variable called Contexts, and here I set it to the following formula: WITH_ITEM(pageVars.Contexts, outputs["HTTP destination request"].resBodyParsed)
  4. I removed the first item in my loop variable, by setting it to this: REMOVE_ITEMS_AT(pageVars.PurchaseOrderInstancesLoop,0) 
  5. I check if the loop variable is empty. 
    • If not, we loop back.
    • If yes, we end the loop and here I just display the Contexts variable.

Hope that helps, and hope I understood what you wanted.