英文:
Dynamics CRM : Typescript - How to create common objects
问题
以下是您要翻译的内容:
"I want to create a common object for security roles so then i don't need to write as static text like
SecurityRoles = {
Role 1 : "Deceased Estate Manager"
Role 2 : "Role2"
}
Similarly if I have common string variables accross files. Where and how do I set these?"
英文:
I am a little new to typescript and have a doubt about how can i create constants files with common objects.
Below is my project structure -
I have placed a common function in XrmV9Utility file -
And i am using this function in my main file as below -
I want to create a common object for security roles so then i don't need to write as static text like
SecurityRoles = {
Role 1 : "Deceased Estate Manager"
Role 2 : "Role2"
}
Similarly if I have common string variables accross files. Where and how do I set these?
答案1
得分: 0
我相信你正在寻找代码中的枚举。你可以像这样创建枚举。
enum Roles {
role1 = "已故房地产经理",
role2 = "角色2"
};
了解更多。
英文:
I believe you are looking for enumerators in your code. You can create enums like this.
enum Roles {
role1 = "Deceased Estate Manager",
role2 = "Role 2"
};
答案2
得分: 0
我尚未完全测试过这个,但我认为这将为您提供一个动态的角色列表:
protected _roles: string[];
private GetRoles(): void {
let select = "?$select=name";
Xrm.WebApi.retrieveMultipleRecords("roles", select).then(
function success(roles) {
if (roles.entities.length > 0) {
for (var i = 0; i < roles.entities.length; i++) {
this._roles.push(roles.entities[i].name);
}
}
},
function (error) {
var alertStrings = { confirmButtonLabel: "Yes", text: error.message, title: "GetRoles Error Response" };
var alertOptions = { height: 120, width: 260 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
})
}
英文:
I haven't fully tested this but I think this would provide a dynamic list of roles for you:
protected _roles: string[];
private GetRoles(): void {
let select = "?$select=name";
Xrm.WebApi.retrieveMultipleRecords("roles", select).then(
function success(roles) {
if (roles.entities.length > 0) {
for (var i = 0; i < roles.entities.length; i++) {
this._roles.push(roles.entities[i].name);
}
}
},
function (error) {
var alertStrings = { confirmButtonLabel: "Yes", text: error.message, title: "GetRoles Error Response" };
var alertOptions = { height: 120, width: 260 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
})
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论