Once you receive the response from the begin assembly session API endpoint, you can display an interview for a work item.
In this Topic Hide
Before displaying an interview in the browser, you must have:
Note: displaying an interview is optional. If you do not want to gather data from a user – for example, if you just want to assemble documents using an existing set of data, without any user intervention – you can skip to the completing an assembly session topic.
An interview is a series of questions used to gather data from your template users. HotDocs generates the questions from the variables and dialogs you define in your template. Once you receive the response from the begin assembly session request, you can use the Core Assembly Service JavaScript API to embed an interview for the assembly session into a web page. The Implementation Steps section of this topic explains these steps in details.
The begin assembly session method provides the following data in its response. You will use this data when displaying the interview in your own web application.
Name | Type | Description |
hdaSessionId | Guid | Identifies the assembly session within Advance. You will need this ID when using other API methods that interact with the assembly session. For example, the save, delete, and complete assembly session endpoints. |
coreSessionId | Guid | Identifies the assembly session within the Core Assembly Service. You will need this ID when using HD$.AttachSession to display the interview in a user's browser. |
interviewJsUrl | String | The URL from which to load the interview.js file. You must include this file in the page on which the interview is displayed. |
serviceMetadataUrl | String | The URL for the current assembly session in the Core Assembly Service. |
To display an interview in your web application requires the following implementation steps:
Create a new endpoint in your application for returning the interview page
This steps are explained in detail below. There is also a complete display interview code example at the end of this topic.
You must first pass the following data to the page on which you want to display the interview:
All of these items of data are retrieved by requests you made when retrieving an access token (either Getting an Access Token using the Resource Owner Flow or Getting an Access Token using the Implicit Flow) and beginning an assembly session.
In an ASP.NET web application, you would typically create a new view model to pass this data to the interview page. For example:
using System;
namespace InterviewTestApp.Models { public class InterviewViewModel { public string ServiceMetadataUrl { get; set; } public string CoreSessionId { get; set; } public Guid WorkItemId { get; set; } public string Token { get; set; } } }
You can then include this model at the top of the page on which you are displaying the interview:
@model InterviewTestApp.Models.InterviewViewModel
To display the interview HTML on your page, you must include an empty div to which Advance can attach the interview HTML. This div must have a unique ID. For example, hdMainDiv. The ID is used later, when configuring the Container property on the HotDocs InterviewOptions.
Your div will look as follows:
<div id="hdMainDiv"></div>
Your web application will have a page on which to display the interview. On this page you must include a script reference to the HotDocs interview.js file, required to display the interview. This will use the interviewJsUrl value passed back in the response from the begin assembly session API call.
When using the example view model from step 1, your reference will look like this:
<script type="text/javascript" src="Model.InterviewJsUrl"></script>
Next, you must configure various options that instruct the interview how to behave. You do this using the IInterviewOptions interface The required properties are:
<script type="text/javascript">
var interviewOptions = { Container: "hdMainDiv", Theme: "default.css", OnInit: () => { HD$.RegisterHandler("OnSessionComplete", (e) => { $.post("CompleteAssemblySession", { Token: "@Model.Token", WorkItemId: "@Model.WorkItemId" }, function() { // Redirect the user to your application's 'Interview Complete' landing page window.location.href = "/Home/LandingPage"; }); }); } };
</script>
You can now use the HD$.AttachSession method to attach the interview to the assembly session. The method call is defined as follows:
HD$.AttachSession(coreSessionId, serviceMetadataUrl, interviewOptions)
When using the example view model from step 1 and the interviewOptions variable from step 4, add a call to attach session below interviewOptions:
HD$.AttachSession(
"@Model.CoreSessionId",
"@Model.ServiceMetadataUrl",
interviewOptions
);
Finally, you need to add an endpoint in your application that will return the interview page when requested by your end-user.
Assuming you are using an ASP.NET web application, and are displaying the interview on the Index.cshtml page, add the following example code to the Index endpoint in your HomeController class:
var interviewViewModel = new InterviewViewModel { ServiceMetadataUrl = assemblySessionData.ServiceMetadataUrl, InterviewJsUrl = assemblySessionData.InterviewJsUrl, CoreSessionId = assemblySessionData.CoreSessionId, WorkItemId = workItemId, Token = token };
return View(interviewViewModel);
Note: this code example assumes that you are using .Net Framework 4.6 and an ASP.NET Web Application project, and have completed the beginning an assembly session topic.
public async Task<ActionResult> Index() { // You should have implemented these methods in the 'Getting an Access Token using the Resource Owner flow' and 'Begin an assembly session' topics var token = await new ResourceOwnerAuthorization().GetResourceOwnerToken(); var assemblySessionData = AssemblySessionHandler.BeginAssemblySession(token);
// The ID of the work item; this must be the same as the one used in 'BeginAssemblySession' var workItemId = Guid.Parse("a1e0e795-5a51-44f5-8fe2-e85a61dbf3c2");
// Create the view model, containing the data required to create the interview var interviewViewModel = new InterviewViewModel { ServiceMetadataUrl = assemblySessionData.ServiceMetadataUrl, InterviewJsUrl = assemblySessionData.InterviewJsUrl, CoreSessionId = assemblySessionData.CoreSessionId, WorkItemId = workItemId, Token = token };
return View(interviewViewModel); }
using System;
namespace AdvanceExampleApplication.Models { public class InterviewViewModel { public string ServiceMetadataUrl { get; set; } public string InterviewJsUrl { get; set; } public string CoreSessionId { get; set; } public Guid WorkItemId { get; set; } public string Token { get; set; } } }
@model AdvanceExampleApplication.Models.InterviewViewModel
// Container div for the interview
<div id="hdMainDiv"></div>
// Interview JavaScript reference
<script type="text/javascript" src="@Model.InterviewJsUrl"></script>
<script type="text/javascript"> // Configure the interview options; this registers the 'OnSessionComplete' event that fires when the user clicks the // interview 'Finish' button. It then posts the data from the interview to your 'CompleteAssemblySession' endpoint.
// You will add the 'CompleteAssemblySession' endpoint in the next topic, 'Completing an Assembly Session'.
// Note that the value for the 'Container' property must match the ID of your interview container div at the top of the page. var interviewOptions = { Container: "hdMainDiv", Theme: "default.css", OnInit: () => { HD$.RegisterHandler("OnSessionComplete", (e) => { $.post("CompleteAssemblySession", { Token: "@Model.Token", WorkItemId: "@Model.WorkItemId" }, function() {
// Redirect the user to your application's 'Interview Complete' landing page window.location.href = "/Home/LandingPage"; }); }); } };
// Attach the assembly session to the interview
HD$.AttachSession( "@Model.CoreSessionId", "@Model.ServiceMetadataUrl", interviewOptions ); </script>