我创建了一个功能区工作台按钮,并添加了一个 JavaScript 操作来在机会表中创建字符串属性(“resource_name”)。但是,当我单击按钮时没有任何反应,既不显示成功也不显示失败。
需要您的专家建议是否更改脚本或采用其他方法。请分享一种通过单击按钮动态创建新属性的方法。 Dynamics 365/PowerApps
使用 JavaScript -
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 tried JS code mentioned above. It will be really helpful if someone can guide me with a better approach to add attributes dynamically in Tables/Entities in MS Dynamics.
为此,您可以调用 HTTP POST Url 并传递有效负载。要调用此 URL,您可以使用 JS 函数或工作流程(我使用工作流程)。
这是要命中的有效负载和 URL
网址:
https://<ORGANIZATION-URL>/api/data/v9.1/EntityDefinitions(LogicalName='<ENTITY-NAME>')/Attributes
有效负载:
{
"SchemaName": "new_fieldname",
"LogicalName": "new_fieldname",
"DisplayName": {
"LocalizedLabels": [
{
"Label": "New Field Title",
"LanguageCode": 1033,
"@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel"
}
],
"@odata.type": "Microsoft.Dynamics.CRM.Label"
},
"RequiredLevel": {
"Value": "None",
"@odata.type": "Microsoft.Dynamics.CRM.AttributeRequiredLevelManagedProperty"
},
"MaxLength": 100,
"@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata"
}
我的测试结果:
我使用邮递员触发我的工作流程,在其中动态传递字段名称、实体名称、架构名称和数据类型
一旦触发,流程就会组成正文并点击 URL。
因此,该表是动态创建的。