Dynamics CRM: Typescript – 如何创建共享对象

huangapple go评论76阅读模式
英文:

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 -

Dynamics CRM: Typescript – 如何创建共享对象

I have placed a common function in XrmV9Utility file -
Dynamics CRM: Typescript – 如何创建共享对象

And i am using this function in my main file as below -

Dynamics CRM: Typescript – 如何创建共享对象

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"
};

Read more.

答案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 = &quot;?$select=name&quot;;  

Xrm.WebApi.retrieveMultipleRecords(&quot;roles&quot;, select).then(
	function success(roles) {
		if (roles.entities.length &gt; 0) {
			for (var i = 0; i &lt; roles.entities.length; i++) {
				this._roles.push(roles.entities[i].name);
			}
		}
	},
	function (error) {
		var alertStrings = { confirmButtonLabel: &quot;Yes&quot;, text: error.message, title: &quot;GetRoles Error Response&quot; };
		var alertOptions = { height: 120, width: 260 };
		Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
	})
}

huangapple
  • 本文由 发表于 2023年2月27日 12:10:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576714.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定