Skip to content

Commit 783fbe5

Browse files
author
Raileen Del Rosario
committed
fixing multiple workflow bug
1 parent 0cfed06 commit 783fbe5

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

examples/Maestro/eg001TriggerWorkflow.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fi
1515
#check that create workflow script ran successfully
1616
workflow_created=$(cat config/WORKFLOW_ID)
1717
if [ -z "$workflow_created" ]; then
18-
echo "please create a worklow before running this example"
18+
echo "Please create and publish a workflow before running this example."
1919
exit 0
2020
fi
2121

@@ -58,11 +58,31 @@ if [[ "$Status" -gt "201" ]]; then
5858
exit 0
5959
fi
6060

61-
echo "Response:"
61+
echo "Workflows found:"
6262
cat $response
6363
echo ""
6464

65-
workflow_id=$(grep -B 1 '"name": "Example workflow - send invite to signer"' $response | grep '"id":' | sed -n 's/.*"id": "\([^"]*\)".*/\1/p')
65+
workflow_ids=$(grep -B 3 -E '"status": "active"' "$response" | grep -B 2 '"name": "Example workflow - send invite to signer"' | grep '"id":' | sed -n 's/.*"id": "\([^"]*\)".*/\1/p')
66+
67+
# Read the existing workflow ID from the config file
68+
config_workflow_id=""
69+
if [ -s config/WORKFLOW_ID ]; then
70+
config_workflow_id=$(cat config/WORKFLOW_ID)
71+
fi
72+
73+
# If there are multiple active workflows, checks if the config_workflow_id is in the workflow list and uses the config_workflow_id.
74+
if [ -n "$config_workflow_id" ] && echo "$workflow_ids" | grep -q "$config_workflow_id"; then
75+
workflow_id="$config_workflow_id"
76+
else
77+
workflow_id=$(echo "$workflow_ids" | head -n 1)
78+
fi
79+
80+
# Error handling if no active workflow ID is found
81+
if [ -z "$workflow_id" ]; then
82+
echo "Error: No active workflow ID found in the response."
83+
echo "Please create and publish a workflow before running this example."
84+
exit 0
85+
fi
6686

6787
#apx-snippet-start:GetWorkflowTriggerRequirements
6888
# Get the trigger URL
@@ -81,7 +101,6 @@ if [[ "$Status" -gt "201" ]]; then
81101
exit 0
82102
fi
83103

84-
echo "Response:"
85104
cat $response
86105
echo ""
87106

examples/Maestro/utils.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fi
88

99

1010
echo "This script uses the package uuidgen to create unique ids for workflow fields. If you do not already have this installed, please visit the Readme at link for installation instructions. If you are on Mac/linux, this is likely already installed."
11-
echo "Press any key to continue"
11+
echo "Press the enter key to continue."
1212
read continue
1313

1414
TEMPLATE_ID=$(cat config/TEMPLATE_ID)
@@ -582,18 +582,20 @@ do
582582
consent_url=`cat $response | grep consentUrl | sed 's/.*\"consentUrl\":\"//' | sed 's/\".*//'`
583583
echo ""
584584
echo "Please grant consent at the following url to publish this workflow: ${consent_url}&host=${redirect_url}"
585-
read -p "Press any key to continue"
585+
read -p "Press the enter key to continue."
586586
else
587587
echo $message
588588
exit 0
589589
fi
590590
else
591591
published="true"
592-
echo $workflow_id >config/WORKFLOW_ID
592+
echo "${workflow_id}" > config/WORKFLOW_ID
593+
echo "Please wait. The workflow is being published. This may take a few seconds."
594+
sleep 8
593595
echo "Successfully created and published workflow ${workflow_id}, ID saved to config/WORKFLOW_ID"
594596
fi
595597
done
596598

597599
# Remove the temporary files
598600
rm "$request_data"
599-
rm "$response"
601+
rm "$response"

0 commit comments

Comments
 (0)