web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Add Attribute Dynamically by Clicking a Button

(0) ShareShare
ReportReport
Posted on by 7
Dear Community,

I've created a Ribbon Workbench button and added an action of JavaScript to create a string attribute('resource_name') in the Opportunity Table. But, when I click on the button nothing happens, it neither shows success nor failure.

Need your expert advice on whether to change the script or to go with another approach. Please share a way to create new attributes dynamically at the click of a button.

Javascript Used - 
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 });
        }
    );
}
 
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 79 Super User 2025 Season 2

#3
TAHER Mehdi Profile Picture

TAHER Mehdi 48

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans