0

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 -

enter image description here

I have placed a common function in XrmV9Utility file - enter image description here

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

enter image description here

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?

MVC_Nhibernate
  • 447
  • 11
  • 30

2 Answers2

0

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.

0

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);
    })
}
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
clintolin
  • 33
  • 5