ASP.NET MVC 5 - DocuSign - Sign On A Document And Track Envelopes

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.
 
ASP.NET MVC 5 - DocuSign - Sign On A Document And Track Envelopes
 
On the DocuSign Portal, the status would be "Need to sign". It's clearly represented in the below image.
 
ASP.NET MVC 5 - DocuSign - Sign On A Document And Track Envelopes 
 
Sign the document by opening an email 
 
Now, let us open the email box to sign on the document. 
 
ASP.NET MVC 5 - DocuSign - Sign On A Document And Track Envelopes 
 
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".
 
ASP.NET MVC 5 - DocuSign - Sign On A Document And Track Envelopes 
 
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.
  1. public ActionResult getEnvelopeInformation()   
  2. {  
  3.     ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");  
  4.     Configuration.Default.ApiClient = apiClient;  
  5.     // provide a valid envelope ID from your account.  
  6.     string envelopeId = "1b59ec10-a7a6-447a-99d4-96136ba7f833"//Enter Stored Envelope Id  
  7.     MyCredential myCredential = new MyCredential();  
  8.     // call the Login() API which sets the user's baseUrl and returns their accountId  
  9.     string accountId = loginApi(myCredential.UserName, myCredential.Password);  
  10.     //===========================================================  
  11.     // Step 2: Get Envelope Information  
  12.     //===========================================================  
  13.     // |EnvelopesApi| contains methods related to creating and sending Envelopes including status calls  
  14.     EnvelopesApi envelopesApi = new EnvelopesApi();  
  15.     Envelope envInfo = envelopesApi.GetEnvelope(accountId, envelopeId);  
  16.     return View();  
  17. // end requestSignatu  
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.
 
ASP.NET MVC 5 - DocuSign - Sign On A Document And Track Envelopes 
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.
  1. public ActionResult getEnvelopeInformation()  
  2. {  
  3.     ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");  
  4.     Configuration.Default.ApiClient = apiClient;  
  5.     // provide a valid envelope ID from your account.  
  6.     string envelopeId = ""//Enter Stored Envelope Id  
  7.     MyCredential myCredential = new MyCredential();  
  8.     // call the Login() API which sets the user's baseUrl and returns their accountId  
  9.     string accountId = loginApi(myCredential.UserName, myCredential.Password);  
  10.     //===========================================================  
  11.     // Step 2: Get Envelope Information  
  12.     //===========================================================  
  13.     // |EnvelopesApi| contains methods related to creating and sending Envelopes including status calls  
  14.     EnvelopesApi envelopesApi = new EnvelopesApi();  
  15.     Envelope envInfo = envelopesApi.GetEnvelope(accountId, envelopeId);  
  16.     if (envInfo.Status == "completed") {  
  17.         DocusignDemo.Models.CSharpCornerEntities cSharpCornerEntities = new DocusignDemo.Models.CSharpCornerEntities();  
  18.         var recipient = cSharpCornerEntities.Recipients.Where(a => a.EnvelopeID == envelopeId).FirstOrDefault();  
  19.         recipient.Status = "completed";  
  20.         recipient.SentOn = System.DateTime.Now;  
  21.         cSharpCornerEntities.Recipients.Attach(recipient);  
  22.         cSharpCornerEntities.SaveChanges();  
  23.     }  
  24.     return View();  
  25. // end requestSignatu  
Now, run your application.
 
ASP.NET MVC 5 - DocuSign - Sign On A Document And Track Envelopes 
 
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
  1. using DocuSign.eSign.Api;  
  2. using DocuSign.eSign.Client;  
  3. using DocuSign.eSign.Model;  
  4. using DocusignDemo.Models;  
  5. using Newtonsoft.Json;  
  6. using System.Collections.Generic;  
  7. using System.Data.Entity;  
  8. using System.IO;  
  9. using System.Linq;  
  10. using System.Web;  
  11. using System.Web.Mvc;  
  12. using Document = DocuSign.eSign.Model.Document;  
  13. namespace DocusignDemo.Controllers {  
  14.     public class DocusignController: Controller {  
  15.         public ActionResult getEnvelopeInformation() {  
  16.             ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");  
  17.             Configuration.Default.ApiClient = apiClient;  
  18.             // provide a valid envelope ID from your account.  
  19.             string envelopeId = ""//Enter Stored Envelope Id  
  20.             MyCredential myCredential = new MyCredential();  
  21.             // call the Login() API which sets the user's baseUrl and returns their accountId  
  22.             string accountId = loginApi(myCredential.UserName, myCredential.Password);  
  23.             //===========================================================  
  24.             // Step 2: Get Envelope Information  
  25.             //===========================================================  
  26.             // |EnvelopesApi| contains methods related to creating and sending Envelopes including status calls  
  27.             EnvelopesApi envelopesApi = new EnvelopesApi();  
  28.             Envelope envInfo = envelopesApi.GetEnvelope(accountId, envelopeId);  
  29.             if (envInfo.Status == "completed") {  
  30.                 DocusignDemo.Models.CSharpCornerEntities cSharpCornerEntities = new DocusignDemo.Models.CSharpCornerEntities();  
  31.                 var recipient = cSharpCornerEntities.Recipients.Where(a => a.EnvelopeID == envelopeId).FirstOrDefault();  
  32.                 recipient.Status = "completed";  
  33.                 recipient.UpdatedOn = System.DateTime.Now;  
  34.                 cSharpCornerEntities.Entry(recipient).State = EntityState.Modified;  
  35.                 cSharpCornerEntities.SaveChanges();  
  36.             }  
  37.             return View();  
  38.         } // end requestSignatu  
  39.         public class MyCredential {  
  40.             public string UserName {  
  41.                 get;  
  42.                 set;  
  43.             } = ""//Docusign Account Username  
  44.             public string Password {  
  45.                 get;  
  46.                 set;  
  47.             } = ""//Docusign Account Password  
  48.         }  
  49.     }  
  50. }  
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.


Similar Articles