Skip to content

Commit 84195ab

Browse files
authored
Merge pull request #8 from docusign/AdvancedRecipientRoutingExamples
The advanced recipient routing examples were added.
2 parents 784cd4d + 3c1d075 commit 84195ab

File tree

11 files changed

+679
-0
lines changed

11 files changed

+679
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ The **refresh token** is not used in this example.
123123
[Create Bulk Send Request](https://developers.docusign.com/esign-rest-api/reference/BulkEnvelopes/BulkSend/createBulkSendRequest).
124124
First, the code creates a bulk send recipients list, and then creates an envelope.
125125
After that, initiates bulk envelope sending.
126+
1. **Pause a signature workflow**
127+
[Source.](./launcher-csharp/eSignature/Controllers/Eg032PauseSignatureWorkflowController.cs)
128+
This code example demonstrates how to create an envelope where the workflow is paused before the envelope is sent to a second recipient using the [Create Envelope](https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create) method.
129+
1. **Unpause a signature workflow**
130+
[Source.](./launcher-csharp/eSignature/Controllers/Eg033UnpauseSignatureWorkflowController.cs)
131+
This code example demonstrates how to update an envelope to resume the workflow that has been paused using the [Update Envelope](https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/update) method.
132+
You must have created at least one envelope with a paused signature workflow.
133+
1. **Conditional recipients**
134+
[Source.](./launcher-csharp/eSignature/Controllers/Eg034ConditionalRecipientsWorkflowController.cs)
135+
This code example demonstrates how to create an envelope where the workflow is routed to different recipients based on the value of a transaction using the [Create Envelope](https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create) method.
126136

127137
## Rooms API
128138
**Note:** to use the Rooms API you must also [create your DocuSign Developer Account for Rooms](https://developers.docusign.com/docs/rooms-api/rooms101/create-account).

launcher-csharp/Common/IRequestItemsService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface IRequestItemsService
1616
string DocumentId { get; set; }
1717
EnvelopeDocuments EnvelopeDocuments { get; set; }
1818
string TemplateId { get; set; }
19+
string PausedEnvelopeId { get; set; }
1920
string Status { get; set; }
2021
public void UpdateUserFromJWT();
2122
public void Logout();

launcher-csharp/Common/RequestItemService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ public string TemplateId {
140140
set => _cache.Set(GetKey("TemplateId"), value);
141141
}
142142

143+
public string PausedEnvelopeId
144+
{
145+
get => _cache.Get<string>(GetKey("PausedEnvelopeId"));
146+
set => _cache.Set(GetKey("PausedEnvelopeId"), value);
147+
}
148+
143149
public string Status { get; set; }
144150

145151
private Account GetAccountInfo(OAuthToken authToken)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@using Microsoft.AspNetCore.Html
2+
@functions
3+
{
4+
IHtmlContent GetTextInputMarkup(string id, string title, string type)
5+
{
6+
return Html.Raw($@"
7+
<div class='form-group'>
8+
<label for= '{id}'>{title}</label >
9+
<input type = '{type}' name = '{id}' id = '{id}' placeholder = '{title}' required class='form-control'/>
10+
</div>");
11+
}
12+
}
13+
14+
<h4>32. Pause a signature workflow.</h4>
15+
16+
<p>
17+
The envelope includes a txt document.
18+
</p>
19+
20+
<p>
21+
Method Envelopes::create creates an envelope where the workflow is paused before the envelope is sent to a second recipient.
22+
</p>
23+
24+
@if (ViewBag.showDoc)
25+
{
26+
<p><a target="_blank" href="@ViewBag.documentation">Documentation</a> about this example.</p>}
27+
28+
<p>
29+
API methods used:
30+
<a target="_blank" href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create">Envelopes::create</a>.
31+
</p>
32+
33+
<p>
34+
View source file <a target="_blank" href="@ViewBag.source">Eg032PauseSignatureWorkflowController.cs</a> on GitHub.
35+
</p>
36+
37+
<form action="" class="eg" method="post" data-busy="form">
38+
39+
<h5 class="mt-4">Signer 1</h5>
40+
<div class="row">
41+
<div class="col-md-6 column">
42+
<div class="form-group">
43+
@GetTextInputMarkup("recipient1.Name", "Signer name", "text")
44+
@GetTextInputMarkup("recipient1.Email", "Signer Email", "email")
45+
</div>
46+
</div>
47+
</div>
48+
49+
50+
<h5 class="mt-4">Signer 2</h5>
51+
<div class="row">
52+
<div class="col-md-6 column ">
53+
<div class="form-group">
54+
@GetTextInputMarkup("recipient2.Name", "Signer name", "text")
55+
@GetTextInputMarkup("recipient2.Email", "Signer Email", "email")
56+
</div>
57+
</div>
58+
</div>
59+
60+
<button type="submit" class="btn btn-primary">Submit</button>
61+
</form>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@using Microsoft.AspNetCore.Html
2+
@functions
3+
{
4+
IHtmlContent GetTextInputMarkup(string id, string title, string type)
5+
{
6+
return Html.Raw($@"
7+
<div class='form-group'>
8+
<label for= '{id}'>{title}</label >
9+
<input type = '{type}' name = '{id}' id = '{id}' placeholder = '{title}' required class='form-control'/>
10+
</div>");
11+
}
12+
}
13+
14+
<h4>33. Unpause a signature workflow.</h4>
15+
16+
<p>
17+
Method Envelopes::update updates an envelope to resume the workflow that has been paused.
18+
</p>
19+
20+
@if (ViewBag.showDoc)
21+
{
22+
<p><a target="_blank" href="@ViewBag.documentation">Documentation</a> about this example.</p>}
23+
24+
<p>
25+
API methods used:
26+
<a target="_blank" href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/update">Envelopes::update</a>.
27+
</p>
28+
29+
<p>
30+
View source file <a target="_blank" href="@ViewBag.source">Eg033UnpauseSignatureWorkflowController.cs</a> on GitHub.
31+
</p>
32+
33+
@if (ViewBag.pausedEnvelopeOk) {
34+
<form action="" class="eg" method="post" data-busy="form">
35+
<button type="submit" class="btn btn-primary">Submit</button>
36+
</form>
37+
}else {
38+
<p>
39+
Problem: please first create an envelope with a paused signature workflow <a href="eg032">example 32.</a> <br />
40+
Thank you.
41+
</p>
42+
43+
<form class="eg" action="eg032" method="get">
44+
<button type="submit" class="btn btn-primary">Continue</button>
45+
</form>
46+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
@using Microsoft.AspNetCore.Html
2+
@functions
3+
{
4+
IHtmlContent GetTextInputMarkup(string id, string title, string type)
5+
{
6+
return Html.Raw($@"
7+
<div class='form-group'>
8+
<label for= '{id}'>{title}</label >
9+
<input type = '{type}' name = '{id}' id = '{id}' placeholder = '{title}' required class='form-control'/>
10+
</div>");
11+
}
12+
}
13+
14+
<h4>34. Conditional recipients.</h4>
15+
16+
<p>
17+
Method Envelopes::create creates an envelope where the workflow is routed to different recipients based on the value of a transaction.
18+
</p>
19+
20+
@if (ViewBag.showDoc)
21+
{
22+
<p><a target="_blank" href="@ViewBag.documentation">Documentation</a> about this example.</p>
23+
}
24+
25+
<p>
26+
API methods used:
27+
<a target="_blank" href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create">Envelopes::create</a>.
28+
</p>
29+
30+
<p>
31+
View source file <a target="_blank" href="@ViewBag.source">Eg034ConditionalRecipientsWorkflowController.cs</a> on GitHub.
32+
</p>
33+
34+
<form action="" class="eg" method="post" data-busy="form">
35+
36+
<h5 class="mt-4">Signer</h5>
37+
<div class="row">
38+
<div class="col-md-6 column">
39+
<div class="form-group">
40+
@GetTextInputMarkup("recipient1.Name", "Signer name", "text")
41+
@GetTextInputMarkup("recipient1.Email", "Signer Email", "email")
42+
</div>
43+
</div>
44+
</div>
45+
46+
<h5 class="mt-4">Conditional signer with unread email</h5>
47+
<div class="row">
48+
<div class="col-md-6 column ">
49+
<div class="form-group">
50+
@GetTextInputMarkup("conditionalRecipient1.Name", "Signer name", "text")
51+
@GetTextInputMarkup("conditionalRecipient1.Email", "Signer Email", "email")
52+
</div>
53+
</div>
54+
</div>
55+
56+
<h5 class="mt-4">Conditional signer with read email</h5>
57+
<div class="row">
58+
<div class="col-md-6 column ">
59+
<div class="form-group">
60+
@GetTextInputMarkup("conditionalRecipient2.Name", "Signer name", "text")
61+
@GetTextInputMarkup("conditionalRecipient2.Email", "Signer Email", "email")
62+
</div>
63+
</div>
64+
</div>
65+
66+
<button type="submit" class="btn btn-primary">Submit</button>
67+
</form>

launcher-csharp/Views/Home/Index.cshtml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,38 @@
348348
<a target="_blank" href="https://developers.docusign.com/esign-rest-api/reference/BulkEnvelopes/BulkSend/createBulkSendList">BulkSend::createBulkSendList</a>
349349
<a target="_blank" href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeRecipients/create">EnvelopeRecipients::create</a>.
350350
</p>
351+
352+
<h2>Advanced recipient routing</h2>
353+
354+
<h4 id="example032">32. <a href="eg032">Pause a signature workflow</a></h4>
355+
356+
<p>
357+
This example creates and envelope and then pauses the signature workflow.
358+
</p>
359+
<p>
360+
API method used:
361+
<a target='_blank' href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create">Envelopes::create</a>.
362+
</p>
363+
364+
<h4 id="example033">33. <a href="eg033">Unpause a signature workflow</a></h4>
365+
366+
<p>
367+
This example unpauses a signature workflow for the previously created envelope that was paused.
368+
</p>
369+
<p>
370+
API method used:
371+
<a target='_blank' href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/update">Envelopes::update</a>.
372+
</p>
373+
374+
<h4 id="example034">34. <a href="eg034">Conditional recipients</a></h4>
375+
376+
<p>
377+
This example creates an envelope that is routed to different recipients based on a predefined condition.
378+
</p>
379+
<p>
380+
API method used:
381+
<a target='_blank' href="https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create">Envelopes::create</a>.
382+
</p>
351383

352384
<!-- anchor-js is only for the index page -->
353385
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.1.1/anchor.min.js"></script>
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using DocuSign.CodeExamples.Controllers;
4+
using DocuSign.CodeExamples.Models;
5+
using DocuSign.eSign.Api;
6+
using DocuSign.eSign.Client;
7+
using DocuSign.eSign.Model;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Newtonsoft.Json;
10+
11+
namespace DocuSign.CodeExamples.eSignature.Controllers
12+
{
13+
[Route("Eg032")]
14+
public class Eg032PauseSignatureWorkflowController : EgController
15+
{
16+
public Eg032PauseSignatureWorkflowController(DSConfiguration config, IRequestItemsService requestItemsService)
17+
: base(config, requestItemsService)
18+
{
19+
ViewBag.title = "Pause a signature workflow";
20+
}
21+
22+
public override string EgName => "Eg032";
23+
24+
[HttpPost]
25+
public IActionResult Create(RecipientModel recipient1, RecipientModel recipient2)
26+
{
27+
// Check the token with minimal buffer time.
28+
bool tokenOk = CheckToken(3);
29+
30+
if (!tokenOk)
31+
{
32+
// We could store the parameters of the requested operation
33+
// so it could be restarted automatically.
34+
// But since it should be rare to have a token issue here,
35+
// we'll make the user re-enter the form data after
36+
// authentication.
37+
RequestItemsService.EgName = EgName;
38+
return Redirect("/ds/mustAuthenticate");
39+
}
40+
41+
string basePath = RequestItemsService.Session.BasePath + "/restapi";
42+
43+
// Step 1. Obtain your OAuth token
44+
string accessToken = RequestItemsService.User.AccessToken;
45+
string accountId = RequestItemsService.Session.AccountId;
46+
47+
// Step 2. Construct your API headers
48+
var apiClient = new ApiClient(basePath);
49+
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
50+
var envelopesApi = new EnvelopesApi(apiClient);
51+
52+
// Step 3. Construct request body
53+
var envelope = CreateEnvelope(recipient1, recipient2);
54+
55+
// Step 4. Call the eSignature API
56+
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelope);
57+
58+
// Process results
59+
RequestItemsService.PausedEnvelopeId = results.EnvelopeId;
60+
ViewBag.h1 = "The envelope was created successfully!";
61+
ViewBag.message = "Results from the Envelopes::create method:";
62+
ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented);
63+
return View("example_done");
64+
}
65+
66+
private EnvelopeDefinition CreateEnvelope(RecipientModel recipient1, RecipientModel recipient2)
67+
{
68+
var document = new Document()
69+
{
70+
DocumentBase64 = "DQoNCg0KDQoJCVdlbGNvbWUgdG8gdGhlIERvY3VTaWduIFJlY3J1aXRpbmcgRXZlbnQNCgkJDQoJCQ0KCQlQbGVhc2UgU2lnbiBpbiENCgkJDQoJCQ0KCQk=",
71+
DocumentId = "1",
72+
FileExtension = "txt",
73+
Name = "Welcome"
74+
};
75+
76+
var workflowStep = new WorkflowStep()
77+
{
78+
Action = "pause_before",
79+
TriggerOnItem = "routing_order",
80+
ItemId = "2"
81+
};
82+
83+
var signer1 = new Signer()
84+
{
85+
Email = recipient1.Email,
86+
Name = recipient1.Name,
87+
RecipientId = "1",
88+
RoutingOrder = "1",
89+
Tabs = new Tabs
90+
{
91+
SignHereTabs = new List<SignHere>
92+
{
93+
new SignHere()
94+
{
95+
DocumentId = "1",
96+
PageNumber = "1",
97+
TabLabel = "Sign Here",
98+
XPosition = "200",
99+
YPosition = "200"
100+
}
101+
}
102+
}
103+
};
104+
105+
var signer2 = new Signer()
106+
{
107+
Email = recipient2.Email,
108+
Name = recipient2.Name,
109+
RecipientId = "2",
110+
RoutingOrder = "2",
111+
Tabs = new Tabs
112+
{
113+
SignHereTabs = new List<SignHere>
114+
{
115+
new SignHere()
116+
{
117+
DocumentId = "1",
118+
PageNumber = "1",
119+
TabLabel = "Sign Here",
120+
XPosition = "300",
121+
YPosition = "200"
122+
}
123+
}
124+
}
125+
};
126+
127+
var envelopeDefinition = new EnvelopeDefinition()
128+
{
129+
Documents = new List<Document> { document },
130+
EmailSubject = "EnvelopeWorkflowTest",
131+
Workflow = new Workflow { WorkflowSteps = new List<WorkflowStep> { workflowStep } },
132+
Recipients = new Recipients { Signers = new List<Signer> { signer1, signer2 } },
133+
Status = "Sent"
134+
};
135+
136+
return envelopeDefinition;
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)