Using a Boolean OnChange to control & disable other Boolean
Today I was asked to implement a new field Boolean field for Ex-Admin but
if this field was true then two other fields
System Admin & Main Admin
Note: All three fields are Bit or Boolean
This had to be a unique selection so that there couldn't be a system admin
set to yes & it also be an Ex-Admin as well. and if the user selected
Ex-admin = Yes then the Main & System admin were defaulted to no and
marked as read only.
So I'm not sure if this is the best way but it worked for me. This was
implemented as a OnChange Only event.
If I added this Script to the OnLoad or OnSave it would clear any
Pre-Selections that had been marked & it also forced the System admin to
yes and greyed out the field when added to the OnLoad piece.
Lastly the alerts at the end was how I figured out what was being sent to
the specific field "true, false, null"
I currently use Microsoft Dynamics 4.0 (Using the Web-Version - I'm not on
the server) Internet Explorer 10
So my question to you all is:
Is there a better way?
Can I implement this for the OnSave or OnLoad with-out changing existing
values?
Can I implement this without making fields greyed out when the ReadOnly
doesn't apply?
Can this be done even when there is a "null" value selected for Ex-Admin?
My Code
//OnChange ExAdmin
//Added by Jeromie Kirchoff 8/21/2013 6:11 PM
var new_FieldDisabled = "";
var new_FieldReadOnly = "";
var new_FieldAdmin = "";
var new_Mainadmin = "";
switch (crmForm.all.new_exadmin.DataValue) {
case false:
new_MainAdmin = false;
new_FieldAdmin = false;
new_FieldDisabled = false;
new_FieldReadOnly = false;
break;
case true:
new_FieldAdmin = false;
new_MainAdmin = false;
new_FieldDisabled = true;
new_FieldReadOnly = true;
break;
}
crmForm.all.new_mainadmin.DataValue = new_MainAdmin;
crmForm.all.new_mainadmin.Disabled = new_FieldDisabled;
crmForm.all.new_mainadmin.ReadOnly = new_FieldReadOnly;
crmForm.all.new_systemadministrator.DataValue = new_FieldAdmin;
crmForm.all.new_systemadministrator.Disabled = new_FieldDisabled;
crmForm.all.new_systemadministrator.ReadOnly = new_FieldReadOnly;
crmForm.all.new_systemadministrator.ForceSubmit = true;
crmForm.all.new_mainadmin.ForceSubmit = true;
//alert( 'Broadbean DataValue: end statement' &
crmForm.all.new_mainadmin.DataValue);
//alert( ("Broadbean Disabled: end statement") &
crmForm.all.new_mainadmin.Disabled);
//alert( "Broadbean DataValue: end statement " &
crmForm.all.new_systemadministrator.DataValue);
//alert( "Broadbean Disabled: end statement " &
crmForm.all.new_systemadministrator.Disabled);
//alert( "Broadbean ReadOnly: end statement " &
crmForm.all.new_systemadministrator.ReadOnly);
No comments:
Post a Comment