RE: crm dynamics 2016 online : how to save the initial value of a field
Hi bardouni,
You could consider following approach:
1. Add both fields to the form and make the initial_validity_date read only (disabled) so that it can't be changed manually
2. add an OnChange event for the validity_date. That method should check if the initial_validity_date is null - and if so, then copy the value from the validity_date to the initial_validity_date.
3. Also , you will have to set the submitmode to always for the initial_validity_date - so that this gets submitted to the CRM Platform.
With the above logic, it will only copy the validity_date to the initial validity date if this never contained any data.
The could could look something like:
function InitializeValidityDate()
{
var pageObj = Xrm.Page;
var initial_validity_date = pageObj.getAttribute("initial_validity_date");
var validity_date_value = pageObj.getAttribute("validity_date").getValue();
if(initial_validity_date.getValue() == null)
{
initial_validity_date.setValue(validity_date_value);
initial_validity_date.setSubmitMode("always");
}
}