Hi Stack community very new to Dynamics CRM development.
I want to achieve the following:
IF Validation Complete equals "Yes" THEN Show field Validated On && Set Validated On field value to UTC now current date, todays date. ELSE Hide field Validated On.
cr253_validationcomplete is a YES/NO field.
Please advise.
function showValidationOnChange (executionContext) {
//Initiated Form Context.
var formContext = executionContext.getFormContext();
var ValidationComplete = formContext.getAttribute("cr253_validationcomplete").getValue();
if (ValidationComplete === true) {
//Using SetVisible propertly for hiding field Account Address.
formContext.getControl("cr253_validatedon").setVisible(true);
formContext.getControl("cr253_validatedon").setValue(Date.now());
}
}
Your code just needs some improvements, in particular the setValue should be used with getAttribute
and to get a new date in JavaScript is new Date()
, also the else
condition is missing, my script has not been tested.
function showValidationOnChange (executionContext) {
//Initiated Form Context.
var formContext = executionContext.getFormContext();
var ValidationComplete = formContext.getAttribute("cr253_validationcomplete").getValue();
if (ValidationComplete === true) {
//Using SetVisible propertly for hiding field Account Address.
formContext.getControl("cr253_validatedon").setVisible(true);
formContext.getAttribute("cr253_validatedon").setValue(new Date());
} else {
formContext.getControl("cr253_validatedon").setVisible(false);
formContext.getAttribute("cr253_validatedon").setValue(null);
}
}