
function addDemoAttribute() {
var entityName = "opportunity";
var attributeName = "resuource_name";
var attributeDisplayName = "Resource Name";
var maxLength = 100;
var description = "A demo attribute integration";
var attributeMetadata = {
"@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
"LogicalName": attributeName,
"DisplayName": {
"LocalizedLabels": [
{
"Label": attributeDisplayName,
"LanguageCode": 1033
}
]
},
"MaxLength": maxLength,
"RequiredLevel": {
"Value": "None"
},
"Description": {
"LocalizedLabels": [
{
"Label": description,
"LanguageCode": 1033
}
]
},
"SchemaName": attributeName
};
var request = {
entity: {
logicalName: entityName
},
MetadataId: null,
AttributeType: 'String',
Attribute: attributeMetadata
};
Xrm.WebApi.online.execute(request).then(
function success(result) {
if (result.ok) {
Xrm.Navigation.openAlertDialog({ text: "Attribute created successfully." });
}
},
function(error) {
Xrm.Navigation.openErrorDialog({ message: "Error creating attribute: " + error.message });
}
);
}