CRM 2016 #Controls #UI #JavaScript #CRM2016 #MoussaElAnnan #Xrm
/* Usage
var fields = ["field1", "field2"];
setAttributesVisibility(reasons, true);
*/
/*
* Function that sets the visibility on an array of columns.
* @param reasons The reasons array.
* @param visibility A boolean that determines the visibility of the control.
*/
setAttributesVisibility = function (reasons, visibility) {
for (var i = 0; i < reasons.length; i++) {
if (Xrm.Page.getControl(reasons[i]) !== null)
Xrm.Page.getControl(reasons[i]).setVisible(visibility);
}
}
/*
Return Value
Type: String
This method will return one of the following string values:
boolean
datetime
decimal
double
integer
lookup
memo
money
optionset
string
*/
/*
* Function that gets the attributes type.
@return {string} The attribute type.
*/
getAttributeFormat = function(){
var attributeType = Xrm.Page.getAttribute(attributeName).getAttributeType();
return attributeType;
}
//Returns whether the control is disabled.
//Type: Boolean. True if the control is disabled, otherwise false.
Xrm.Page.getControl(arg).getDisabled();
//Sets whether the control is disabled.
//Type: Boolean. True if the control should be disabled, otherwise false.
Xrm.Page.getControl(arg).setDisabled(bool);
//Returns a value that categorizes controls.
Xrm.Page.getControl(arg).getControlType()
/* Usage
var fields = ["field1", "field2"];
clearAttributesValues(fields);
*/
/*
* Function that clears the values of an array of attributes.
* @params attributes The array of attributes.
*/
clearAttributesValues = function (attributes) {
for (var i = 0; i < attributes.length; i++) {
if (Xrm.Page.getAttribute(attributes[i]) !== null)
Xrm.Page.getAttribute(attributes[i]).setValue(null);
}
}