Introduction
In this article, we will see how to track the Envelope status to find out whether the recipient(s) signed a particular document or not using envelope id. Please take a look at my previous articles for basic account creation, integration, validation, and creation of a signature request on a document and storing the envelope information for the respective recipient(s) within our application.
Let's move forward to track the Envelope status.
Prerequisites
- Visual Studio
- Basic knowledge of ASP.NET MVC
- Basic knowledge of C#
- Should have an account on DocuSign
Article Flow
- View the status of Envelope before signing on the document
- Sign the document by opening the email
- View the status after signing on the document on the DocuSign portal
- View the status after signing on the document using our web application
- Update the status in the database
View the status of Envelope before signing on the document
In the below image, you can see that the Envelope status is 'sent' after making the signing request to the recipient. We have stored this envelope summary information in our local database for our future use.
On the DocuSign Portal, the status would be "Need to sign". It's clearly represented in the below image.
Sign the document by opening an email
Now, let us open the email box to sign on the document.
Once you click on the "REVIEW DOCUMENT" button, it will redirect you to the DocuSign portal to sign on the respective document. While signing on the document, you can draw your own signature or you can choose among the signatures given by the DocuSign portal. The signature will be generated based on your first name and second name.
View the status after signing on the document on the DocuSign Portal
As a user, we have signed on the document by opening our mailbox. Now, as an admin, let us open the DocuSign account and check the status of the respective recipient envelope. In the below image, you can see that the status has been changed from "need to sign" to "Completed".
Now, let us check in our application.
View the status after signing on the document using our web application
Now, write the below code to get the envelope information by passing the envelope id.
- public ActionResult getEnvelopeInformation()
- {
- ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
- Configuration.Default.ApiClient = apiClient;
-
- string envelopeId = "1b59ec10-a7a6-447a-99d4-96136ba7f833";
- MyCredential myCredential = new MyCredential();
-
- string accountId = loginApi(myCredential.UserName, myCredential.Password);
-
-
-
-
- EnvelopesApi envelopesApi = new EnvelopesApi();
- Envelope envInfo = envelopesApi.GetEnvelope(accountId, envelopeId);
- return View();
- }
Now, run your application. In the below image, you can see the status of the Envelope. The "Completed" status represents that the recipient signature process is completed on the respective document.
After the completion of the signing process, the user/client will get an email as "Your document has been completed". Now, the client/user is able to download or share the document by clicking "View Completed Document".
But still, we have the status is "sent" for this envelope in our database and we have to update the status to "completed".
Update the status in the database
Let's update the database record for respective envelope while the status comes to the "Completed" stage.
- public ActionResult getEnvelopeInformation()
- {
- ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
- Configuration.Default.ApiClient = apiClient;
-
- string envelopeId = "";
- MyCredential myCredential = new MyCredential();
-
- string accountId = loginApi(myCredential.UserName, myCredential.Password);
-
-
-
-
- EnvelopesApi envelopesApi = new EnvelopesApi();
- Envelope envInfo = envelopesApi.GetEnvelope(accountId, envelopeId);
- if (envInfo.Status == "completed") {
- DocusignDemo.Models.CSharpCornerEntities cSharpCornerEntities = new DocusignDemo.Models.CSharpCornerEntities();
- var recipient = cSharpCornerEntities.Recipients.Where(a => a.EnvelopeID == envelopeId).FirstOrDefault();
- recipient.Status = "completed";
- recipient.SentOn = System.DateTime.Now;
- cSharpCornerEntities.Recipients.Attach(recipient);
- cSharpCornerEntities.SaveChanges();
- }
- return View();
- }
Now, run your application.
Again, we haven't updated the document, right? In the next article, we will see how to get the signed document in the web application and update in our database.
Complete Controller Code
- using DocuSign.eSign.Api;
- using DocuSign.eSign.Client;
- using DocuSign.eSign.Model;
- using DocusignDemo.Models;
- using Newtonsoft.Json;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.IO;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using Document = DocuSign.eSign.Model.Document;
- namespace DocusignDemo.Controllers {
- public class DocusignController: Controller {
- public ActionResult getEnvelopeInformation() {
- ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
- Configuration.Default.ApiClient = apiClient;
-
- string envelopeId = "";
- MyCredential myCredential = new MyCredential();
-
- string accountId = loginApi(myCredential.UserName, myCredential.Password);
-
-
-
-
- EnvelopesApi envelopesApi = new EnvelopesApi();
- Envelope envInfo = envelopesApi.GetEnvelope(accountId, envelopeId);
- if (envInfo.Status == "completed") {
- DocusignDemo.Models.CSharpCornerEntities cSharpCornerEntities = new DocusignDemo.Models.CSharpCornerEntities();
- var recipient = cSharpCornerEntities.Recipients.Where(a => a.EnvelopeID == envelopeId).FirstOrDefault();
- recipient.Status = "completed";
- recipient.UpdatedOn = System.DateTime.Now;
- cSharpCornerEntities.Entry(recipient).State = EntityState.Modified;
- cSharpCornerEntities.SaveChanges();
- }
- return View();
- }
- public class MyCredential {
- public string UserName {
- get;
- set;
- } = "";
- public string Password {
- get;
- set;
- } = "";
- }
- }
- }
Refer to the attached project. I have attached the demonstrated project without a package due to the size limit. Wait for my next DocuSign article to get more knowledge on this.
Summary
In this article, we discussed how to track the Envelope status to find out whether the Recipient has signed the particular document using envelope id or not. Also, we saw the process of updating the envelope status in the database. I hope it will help you out. Your valuable feedback and comments about this article are always welcome.