This allows to write field triggers that utilize Virtual Fields and other objects which do not always trigger rules themselves. Since custom field changes always execute field triggers, accessing Virtual Fields inside such triggers will read correct values.
Following screenshots demonstrate how [CX.NOW] behaves compared to [CX.NOW1] and [CX.NOW2] which are assigned to DateTime.Now and Now via standard Encompass field calculations. All three fields are included on the Test form provided in EMPKG.
All test screenshots include Loan Monitor output tracing/displaying exact field changes.
Code used in this plugin (C#):
using System;
using System.Collections.Generic;
using System.Text;
using EllieMae.Encompass.ComponentModel;
using EllieMae.Encompass.Automation;
using EllieMae.Encompass.BusinessObjects.Loans;
namespace CxNowAtLoanOpenAndSave
{
[Plugin]
public class EncompassPlugin
{
// Constructor - wait for Login event
public EncompassPlugin()
{
EncompassApplication.Login += new EventHandler(Application_Login);
}
// Login - handle Loan Open and Loan Closing events
private void Application_Login(object sender, EventArgs e)
{
EncompassApplication.LoanOpened += new EventHandler(LoanOpenedEvent);
EncompassApplication.LoanClosing += new EventHandler(LoanClosingEvent);
}
// Loan Opened event - start monitoring BeforeCommit
private void LoanOpenedEvent(object sender, EventArgs e)
{
EncompassApplication.CurrentLoan.BeforeCommit += new CancelableEventHandler(BeforeCommitEvent);
SetCxNowField();
}
// Loan Closing event - stop monitoring BeforeCommit
private void LoanClosingEvent(object sender, EventArgs e)
{
EncompassApplication.CurrentLoan.BeforeCommit -= new CancelableEventHandler(BeforeCommitEvent);
}
// Before Commit - set CX.NOW = Now so that stuff can trigger off it
private void BeforeCommitEvent(object source, CancelableEventArgs e)
{
SetCxNowField();
}
// Set [CX.NOW] field - must be STRING 20-character
private void SetCxNowField()
{
try
{
Loan loan = EncompassApplication.CurrentLoan;
if (loan != null)
{
loan.Fields["CX.NOW"].Value = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("SetCxNowField Error: " + ex.Message);
}
}
}
}