Util-CommandBar.js
RunFlowPDFSigningIndividual
Global Variables
Global Variables
const EnvironmentVariableAPIIndividualAgreementFromDA = "tt_api_IndividualAgreementFromDocumentApproval";
Code
RunFlowPDFSigningIndividual(formContext, approvalIDWithBraces)
async function RunFlowPDFSigningIndividual(formContext, approvalIDWithBraces)
{
try {
if (approvalIDWithBraces.length <= 0) throw new Error ("Document Approval ID not provided to RunFlowPDFSigningIndividual().");
const approvalID = approvalIDWithBraces.slice(1, -1);
const bpfTablePluralName = "tt_documentapproavalbpfs";
const bpfProcessId = "fc6fdebe-d869-ef11-a670-6045bd1139c4";
// GET Business Process Flow Instance properties
const bpfiProperties = await GetBusinessProcessFlowInstance(bpfTablePluralName, "tt_documentapproval", approvalID, bpfProcessId);
if (!bpfiProperties) throw new Error ("Error in ValidateDetails: GetBusinessProcessFlowInstance failed.");
const bpfiId = bpfiProperties.businessprocessflowinstanceid;
// Return early if Flow is already running
const agreementProcessingObj = retrieveWebAPIData("tt_documentapprovals", "tt_agreementprocessing", "tt_documentapprovalid eq " + approvalID, "");
if (agreementProcessingObj?.value?.length != 1) throw new Error ("Multiple tt_documentapproval rows detected.");
const agreementProcessing = agreementProcessingObj.value[0].tt_agreementprocessing;
if (agreementProcessing == 1) {
RunFlowPDFSigningInProgress();
return false;
}
// Magic strings
const idNotificationHelp = "idNotifyContactOnBPFStage"; // Notification set by NotifyContactOnBPFStage() in DocumentApproval.js
// Clear help notification
formContext.ui.clearFormNotification(idNotificationHelp);
// Set in progress notification
const idNotificationProcessing = "idIndividualAgreement";
formContext.ui.setFormNotification("Creating PDF agreement for Contact...", "INFORMATION", idNotificationProcessing);
const url = GetEnvironmentVariableValue(EnvironmentVariableAPIIndividualAgreementFromDA); // HTTP POST URL for Flow "PDF Signing - Create Individual Agreement from Document Approval"
const data = {
"documentApprovalID": approvalID
};
try {
// Set flag to indicate Flow is running
PatchWebAPIData("tt_documentapprovals", { "tt_agreementprocessing": true }, approvalID);
const response = await RunFlow(url, data);
const responseObj = await response.json();
formContext.ui.clearFormNotification(idNotificationProcessing);
if (response.status === 200) {
formContext.ui.setFormNotification(responseObj.flow_status_detail, "INFORMATION");
const success = await OnKYCCheckProcessStageSetLetterOfEngagementSent(formContext, approvalID);
if (!success) throw new Error ("OnKYCCheckProcessStageSetLetterOfEngagementSent did not complete successfully.");
} else if (response.status === 202) {
formContext.ui.setFormNotification("Processing data with Adobe Sign... Please note that this may take a minute or two to complete.", "INFORMATION", "id202Response");
const flowStatusUrl = response.headers.get('Location');
Check202FlowStatus(formContext, flowStatusUrl, RunFlowPDFSigningSuccessCallback, RunFlowPDFSigningFailureCallback, ["tt_documentapprovals", approvalID, responseObj.flow_status_detail]);
} else if (response.status === 400) {
formContext.ui.setFormNotification(responseObj.flow_status_detail, "ERROR");
throw new Error ("Flow returned a 400.");
} else {
throw new Error ("Unknown error occurred.");
}
} catch (error) {
// Reset flag to indicate Flow has completed
PatchWebAPIData("tt_documentapprovals", { "tt_agreementprocessing": false }, approvalID);
throw error;
}
// Reset flag to indicate Flow has completed
PatchWebAPIData("tt_documentapprovals", { "tt_agreementprocessing": false }, approvalID);
/*
// Set Aproval BPF to Finished
const dataPatchBPFI = {
"statuscode": 2
};
PatchWebAPIData(bpfTablePluralName, dataPatchBPFI, bpfiId);
// Set Approval BPF flag for notification
PatchWebAPIData("tt_documentapprovals", { "tt_isdocumentapprovalsentforsignatureindividual": true }, approvalID);
// **** This openForm needs to be deleted *********************************************
// Re-open the form
Xrm.Navigation.openForm({
entityId: approvalID,
entityName: "tt_documentapproval"
});
*/
} catch (error) {
console.error(error);
formContext.ui.setFormNotification("Something went wrong. Please contact your Practice Gateway support team", "ERROR");
}
}
RunFlowPDFSigningDataApprovers
Global Variables
Global Variables
const EnvironmentVariableAPIDataApproverAgreementFromDA = "tt_api_DataApproverAgreementFromDocumentApproval";
Code
RunFlowPDFSigningDataApprovers(formContext, approvalIDWithBraces)
async function RunFlowPDFSigningDataApprovers(formContext, approvalIDWithBraces)
{
try {
if (approvalIDWithBraces.length <= 0) throw new Error ("Document Approval ID not provided to RunFlowPDFSigningDataApprovers().");
const approvalID = approvalIDWithBraces.substring(1, approvalIDWithBraces.length - 1);
const bpfTablePluralName = "tt_documentapproavalbpfs";
const bpfProcessId = "fc6fdebe-d869-ef11-a670-6045bd1139c4";
// GET Business Process Flow Instance properties
const bpfiProperties = await GetBusinessProcessFlowInstance(bpfTablePluralName, "tt_documentapproval", approvalID, bpfProcessId);
if (!bpfiProperties) throw new Error ("Error in ValidateDetails: GetBusinessProcessFlowInstance failed.");
const bpfiId = bpfiProperties.businessprocessflowinstanceid;
// Return early if Flow is already running
const agreementProcessingObj = retrieveWebAPIData("tt_documentapprovals", "tt_agreementprocessing", "tt_documentapprovalid eq " + approvalID, "");
if (agreementProcessingObj?.value?.length != 1) throw new Error ("Multiple tt_documentapproval rows detected.");
const agreementProcessing = agreementProcessingObj.value[0].tt_agreementprocessing;
if (agreementProcessing == 1) {
RunFlowPDFSigningInProgress();
return false;
}
// Magic strings
const idNotificationHelp = "idNotifyContactOnBPFStage"; // Notification set by NotifyContactOnBPFStage() in DocumentApproval.js
// Clear help notification
formContext.ui.clearFormNotification(idNotificationHelp);
// Set in progress notification
const idNotificationProcessing = "idDataApproverAgreement";
formContext.ui.setFormNotification("Creating PDF Agreement for Data Approvers...", "INFORMATION", idNotificationProcessing);
const url = GetEnvironmentVariableValue(EnvironmentVariableAPIDataApproverAgreementFromDA); // HTTP POST URL for Flow "Send Welcome Back Email to Contact"
const data = {
"documentApprovalID": approvalID
};
try {
// Set flag to indicate Flow is running
PatchWebAPIData("tt_documentapprovals", { "tt_agreementprocessing": true }, approvalID);
const response = await RunFlow(url, data);
const responseObj = await response.json();
formContext.ui.clearFormNotification(idNotificationProcessing);
if (response.status === 200) {
formContext.ui.setFormNotification(responseObj.flow_status_detail, "INFORMATION");
const success = await OnKYCCheckProcessStageSetLetterOfEngagementSent(formContext, approvalID);
if (!success) throw new Error ("OnKYCCheckProcessStageSetLetterOfEngagementSent did not complete successfully.");
} else if (response.status === 202) {
formContext.ui.setFormNotification("Processing data with Adobe Sign... Please note that this may take a minute or two to complete.", "INFORMATION", "id202Response");
const flowStatusUrl = response.headers.get('Location');
Check202FlowStatus(formContext, flowStatusUrl, RunFlowPDFSigningSuccessCallback, RunFlowPDFSigningFailureCallback, ["tt_documentapprovals", approvalID, responseObj.flow_status_detail]);
} else if (response.status === 400) {
formContext.ui.setFormNotification(responseObj.flow_status_detail, "ERROR");
throw new Error ("Flow returned a 400.");
} else {
throw new Error ("Unknown error occurred.");
}
} catch (error) {
// Reset flag to indicate Flow has completed
PatchWebAPIData("tt_documentapprovals", { "tt_agreementprocessing": false }, approvalID);
throw error;
}
// Reset flag to indicate Flow has completed
PatchWebAPIData("tt_documentapprovals", { "tt_agreementprocessing": false }, approvalID);
/*
// Set KYC BPF to Finished
const dataPatchBPFI = {
"statuscode": 2
};
PatchWebAPIData(bpfTablePluralName, dataPatchBPFI, bpfiId);
// Set Approval BPF flag for notification
PatchWebAPIData("tt_documentapprovals", { "tt_isdocumentapprovalsentforsignatureapproval": true }, approvalID);
// **** This openForm needs to be deleted *********************************************
// Re-open the form
Xrm.Navigation.openForm({
entityId: approvalID,
entityName: "tt_documentapproval"
});
*/
} catch (error) {
console.error(error);
formContext.ui.setFormNotification("Something went wrong. Please contact your Practice Gateway support team", "ERROR");
}
}
RunFlowPDFSigningListIndividual
Global Variables
Global Variables
const EnvironmentVariableAPIIndividualAgreementFromList = "tt_api_IndividualAgreementsfromList";
Code
RunFlowPDFSigningListIndividual(formContext, approvalIDWithBraces)
async function RunFlowPDFSigningListIndividual(formContext, listIDWithBraces, approvalID)
{
if (listIDWithBraces.length <= 0) {
console.error("List ID not provided to RunFlowPDFSigningListIndividual().");
return false;
}
const listID = listIDWithBraces.slice(1, -1);
// Return early if Flow is already running
try {
const agreementProcessingObj = retrieveWebAPIData("lists", "tt_agreementprocessing", "listid eq " + listID, "");
if (agreementProcessingObj?.value?.length != 1) { throw "Multiple list rows detected."; }
const agreementProcessing = agreementProcessingObj.value[0].tt_agreementprocessing;
if (agreementProcessing == 1) {
RunFlowPDFSigningInProgress();
return false;
}
} catch (error) {
console.error("Error in RunFlowPDFSigningListIndividual - unable to retrieve Agreement Processing value: ", error);
formContext.ui.setFormNotification("Server error. Please contact your Practice Gateway support team.", "ERROR");
}
const idNotificationProcessing = "idIndividualList";
formContext.ui.setFormNotification("Creating individual PDF agreements for List members...", "INFORMATION", idNotificationProcessing);
const url = GetEnvironmentVariableValue(EnvironmentVariableAPIIndividualAgreementFromList); // HTTP POST URL for Flow "PDF Signing - Create Individual Agreements from List"
const data = {
"marketingListID": listID
};
try {
// Set flag to indicate Flow is running
PatchWebAPIData("lists", { "tt_agreementprocessing": true }, listID);
const response = await RunFlow(url, data);
const responseObj = await response.json();
formContext.ui.clearFormNotification(idNotificationProcessing);
if (response.status && response.status != 202) { // patch is handled in 202 callbacks
// Reset flag to indicate Flow has completed
PatchWebAPIData("lists", { "tt_agreementprocessing": false }, listID);
}
if (response.status === 200) {
formContext.ui.setFormNotification(responseObj.flow_status_detail, "INFORMATION");
} else if (response.status === 202) {
formContext.ui.setFormNotification("Processing data with Adobe Sign... Please note that this may take a minute or two to complete.", "INFORMATION", "id202Response");
const flowStatusUrl = response.headers.get('Location');
Check202FlowStatus(formContext, flowStatusUrl, RunFlowPDFSigningSuccessCallback, RunFlowPDFSigningFailureCallback, ["lists", listID, responseObj.flow_status_detail, approvalID]);
} else if (response.status === 400) {
formContext.ui.setFormNotification(responseObj.flow_status_detail, "ERROR");
} else {
console.error("Unknown error");
console.table(response);
formContext.ui.setFormNotification("Processing error. Please contact your Practice Gateway support team.", "ERROR");
}
} catch (error) {
console.error("API call failed:", error);
formContext.ui.setFormNotification("Server error. Please contact your Practice Gateway support team.", "ERROR");
// Reset flag to indicate Flow has completed
PatchWebAPIData("lists", { "tt_agreementprocessing": false }, listID);
}
return true;
}
RunFlowPDFSigningListMultiple
Global Variables
Global Variables
const EnvironmentVariableAPISharedAgreementFromList = "tt_api_JointAgreementfromList";
Code
RunFlowPDFSigningListMultiple(formContext, approvalIDWithBraces)
async function RunFlowPDFSigningListMultiple(formContext, listIDWithBraces)
{
if (listIDWithBraces.length <= 0) {
console.error("List ID not provided to RunFlowPDFSigningListMultiple().");
return false;
}
const listID = listIDWithBraces.slice(1, -1);
// Return early if Flow is already running
try {
const agreementProcessingObj = retrieveWebAPIData("lists", "tt_agreementprocessing", "listid eq " + listID, "");
if (agreementProcessingObj?.value?.length != 1) { throw "Multiple list rows detected."; }
const agreementProcessing = agreementProcessingObj.value[0].tt_agreementprocessing;
if (agreementProcessing == 1) {
RunFlowPDFSigningInProgress();
return false;
}
} catch (error) {
console.error("Error in RunFlowPDFSigningListMultiple - unable to retrieve Agreement Processing value: ", error);
formContext.ui.setFormNotification("Server error. Please contact your Practice Gateway support team.", "ERROR");
}
const idNotificationProcessing = "idSharedList";
formContext.ui.setFormNotification("Creating joint PDF agreement for List members...", "INFORMATION", idNotificationProcessing);
const url = GetEnvironmentVariableValue(EnvironmentVariableAPISharedAgreementFromList); // HTTP POST URL for Flow "PDF Signing - Create Joint Agreement from List"
const data = {
"marketingListID": listID
};
try {
// Set flag to indicate Flow is running
PatchWebAPIData("lists", { "tt_agreementprocessing": true }, listID);
const response = await RunFlow(url, data);
const responseObj = await response.json();
formContext.ui.clearFormNotification(idNotificationProcessing);
if (response.status && response.status != 202) { // patch is handled in 202 callbacks
// Reset flag to indicate Flow has completed
PatchWebAPIData("lists", { "tt_agreementprocessing": false }, listID);
}
if (response.status === 200) {
formContext.ui.setFormNotification(responseObj.flow_status_detail, "INFORMATION");
} else if (response.status === 202) {
formContext.ui.setFormNotification("Processing data with Adobe Sign... Please note that this may take a minute or two to complete.", "INFORMATION", "id202Response");
const flowStatusUrl = response.headers.get('Location');
Check202FlowStatus(formContext, flowStatusUrl, RunFlowPDFSigningSuccessCallback, RunFlowPDFSigningFailureCallback, ["lists", listID, responseObj.flow_status_detail, approvalID]);
} else if (response.status === 400) {
formContext.ui.setFormNotification(responseObj.flow_status_detail, "ERROR");
} else {
console.error("Unknown error");
console.table(response);
formContext.ui.setFormNotification("Processing error. Please contact your Practice Gateway support team.", "ERROR");
}
} catch (error) {
console.error("API call failed:", error);
formContext.ui.setFormNotification("Server error. Please contact your Practice Gateway support team.", "ERROR");
// Reset flag to indicate Flow has completed
PatchWebAPIData("lists", { "tt_agreementprocessing": false }, listID);
}
}