Hi @sdnd2000
Based on our understanding, you're trying to make some custom fields mandatory through JavaScript. To achieve this, follow the steps below
- Go to the basic Form.
- Select your form.
- Select additional settings.
- In the custom JavaScript section, paste the code mentioned below:

if (window.jQuery) {
(function ($) {
$(document).ready(function () {
$("#iric_endtime, #iric_starttime, #iric_account").addClass("required");
$(".required").each(function() {
var labelText = $(this).prev().not('input').not('br').not('select').text();
$(this).prev().not('input').not('br').not('select').html(labelText +
'<span style="color: red;"> *</span>');
});
if (typeof (Page_Validators) ==
'undefined') return;
// Create new validator for end time
var endtimeValidator = document.createElement('span');
endtimeValidator.style.display = "none";
endtimeValidator.id = "endtimeValidator";
endtimeValidator.controltovalidate = "iric_endtime";
// end time field logical name
endtimeValidator.errormessage = "<a href='#iric_endtime_label' referencecontrolid='iric_endtime' onclick='javascript:scrollToAndFocus(\"iric_endtime_label\",\"iric_endtime\");return false;'>End time is a required field.</a>";
endtimeValidator.validationGroup = "";
// Set this if you have set ValidationGroup on the form
endtimeValidator.initialvalue = "";
endtimeValidator.evaluationfunction = function () {
var endtimeValue = $("#iric_endtime").val();
// end time field logical name
if (endtimeValue ==
"") {
return false;
// return false to trigger validation failure
}
return true;
};
// Create new validator for lookup filed
var lookupValidator = document.createElement('span');
lookupValidator.style.display = "none";
lookupValidator.id = "lookupValidator";
lookupValidator.controltovalidate = "iric_account";
// lookup field logical name
lookupValidator.errormessage = "<a href='#iric_account_label' referencecontrolid='iric_account' onclick='javascript:scrollToAndFocus(\"iric_account_label\",\"iric_account\");return false;'>Account is required field.</a>";
lookupValidator.validationGroup = "";
// Set this if you have set ValidationGroup on the form
lookupValidator.initialvalue = "";
lookupValidator.evaluationfunction = function () {
var lookupValue = $("#iric_account").val();
// Lookup field logical name
if (lookupValue ==
"") {
return false;
}
return true;
};
// Add the end time validator to the page validators array
Page_Validators.push(endtimeValidator);
Page_Validators.push(lookupValidator);
});
}(window.jQuery));
}
To reflect the change save and sync
Thanks!
Inogic Professional Service Division
An expert technical extension for your techno-functional business needs
Power Platform/Dynamics 365 CRM
Drop an email at crm@inogic.com
Service: http://www.inogic.com/services/
Power Platform/Dynamics 365 CRM Tips and Tricks: http://www.inogic.com/blog/