guusvanw
guusvanw

Reputation: 41

CRM 2011 & Typescript: How to get sections within a tab

We're implementing our client-side logic using TypeScript on one of our CRM 2011 projects. So far, so good.

However, something seems off in the Xrm2011.1_0.d.ts file regarding sections. Tabs and sections are defined as follows:

module Xrm {
    export module Page {
        ...
        export module ui {
            ...
            export module tabs {
                ...
                export function get(tabName: string): Tab;
                ...
                export module sections {
                    ...
                    export function get(sectionName: string): Section;
                    ...
                }
            }
        }
    }
}

This forces you to implement typescript as such:

var section = <Xrm.Page.Section>Xrm.Page.ui.tabs.sections.get(sectionName);

Which compiles to:

Xrm.Page.ui.tabs.sections.get(sectionName); 

However, the correct JavaScript syntax should be:

Xrm.Page.ui.tabs.get(tabName).sections.get(sectionName);

Has anyone experienced this? Am I missing something here?

Thanks in advance.

Upvotes: 4

Views: 770

Answers (2)

SteveD
SteveD

Reputation: 1

var section = <Xrm.Page.Section>Xrm.Page.ui.tabs.get(tabName).sections.get(sectionName);

will compile in the way you specified in the "correct javascript syntax should be" bit.

Upvotes: 0

Scott
Scott

Reputation: 11

The last syntax won't work. Tab isn't a class so tabs.get is returning a Tb class but the Tab class doesn't have a .sections property. You also shouldn't need to cast.

Ps.... Try declaring your modules with dot notation "export Xrm.Page.ui.tabs". It will make you code more readable.

Also, what made you make some classes capital case and some not?

Upvotes: 1

Related Questions