Skip to content

Commit 4bb63dc

Browse files
author
Raileen Del Rosario
committed
adding error handling and multiple app choice handling
1 parent 7e8a54e commit 4bb63dc

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

examples/ConnectedFields/eg001SetConnectedFields.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,24 @@ extract_verify_info() {
5959

6060
prompt_user_choice() {
6161
local json_data="$1"
62-
local apps=( $(echo "$json_data" | jq -r '.[] | .appId') )
63-
mapfile -t names < <(echo "$json_data" | jq -r '.[] | .tabs[0].extensionData.applicationName')
64-
62+
mapfile -t unique_apps < <(echo "$json_data" | jq -r '[.[] | {appId: .appId, applicationName: .tabs[0].extensionData.applicationName}] | unique_by(.appId) | .[] | "\(.appId) \(.applicationName)"')
6563

6664
if [[ -z "$json_data" || "$json_data" == "[]" ]]; then
67-
echo "Error: No verification apps found in the data."
65+
echo "No data verification were found in the account. Please install a data verification app."
66+
echo ""
67+
echo "You can install a phone number verification extension app by copying the following link to your browser: "
68+
echo "https://apps.docusign.com/app-center/app/d16f398f-8b9a-4f94-b37c-af6f9c910c04"
6869
exit 1
6970
fi
7071

7172
echo "Please select an app by entering a number:"
72-
for i in "${!names[@]}"; do
73-
echo "$((i+1)). ${names[$i]}"
73+
for i in "${!unique_apps[@]}"; do
74+
echo "$((i+1)). ${unique_apps[$i]#* }"
7475
done
7576

76-
read -p "Enter choice (1-${#names[@]}): " choice
77-
if [[ "$choice" =~ ^[1-${#names[@]}]$ ]]; then
78-
chosen_app_id="${apps[$((choice-1))]}"
77+
read -p "Enter choice (1-${#unique_apps[@]}): " choice
78+
if [[ "$choice" =~ ^[1-${#unique_apps[@]}]$ ]]; then
79+
chosen_app_id="${unique_apps[$((choice-1))]%% *}"
7980
selected_data=$(echo "$json_data" | jq --arg appId "$chosen_app_id" '[.[] | select(.appId == $appId)]')
8081
parse_verification_data "$selected_data"
8182
else
@@ -126,7 +127,10 @@ fi
126127
filtered_data=$(extract_verify_info)
127128

128129
if [[ -z "$filtered_data" || "$filtered_data" == "[]" ]]; then
129-
echo "Error: No verification data found in response file."
130+
echo "No data verification were found in the account. Please install a data verification app."
131+
echo ""
132+
echo "You can install a phone number verification extension app by copying the following link to your browser: "
133+
echo "https://apps.docusign.com/app-center/app/d16f398f-8b9a-4f94-b37c-af6f9c910c04"
130134
exit 1
131135
fi
132136

0 commit comments

Comments
 (0)