JavaScript with Dynamics CRM – 2

Posted by

Now since we have covered Environment set up, naming conventions, some best practices here, Now in this article, I am going to focus basic Javascript functions, which are commonly used in JavaScript extension of Dynamics CRM.

1. Read value from a control –

Xrm.Page.getAttribute(“bats_clientcode”).getValue();

2. Assigning Value to a control –

For two option set (with true or false)

    Xrm.Page.getAttribute(“bats_staffingsolution”).setValue(false);

For Option set (set the numeric value for specific item)

Xrm.Page.getAttribute(“bats_clientstatus”).setValue(500000000);

For text box

Xrm.Page.getAttribute(“bats_clientName”).setValue(“Atul Sharma”);

3. Hide or Show –

Hide/Show a tab 

Xrm.Page.ui.tabs.get(TAB_BASIC).setVisible(false);

Xrm.Page.ui.tabs.get(TAB_BASIC).setVisible(true);

Hide/Show a section

Xrm.Page.ui.tabs.get(TAB_BASIC).sections.get(SEC_ADDRESS).setVisible(false);

Xrm.Page.ui.tabs.get(TAB_BASIC).sections.get(SEC_ADDRESS).setVisible(true);

Hide/Show a control

Xrm.Page.ui.controls.get(“bats_clientRevenue”).setVisible(true);

Xrm.Page.ui.controls.get(“bats_clientRevenue”).setVisible(false);

4. Enable or Disable –

Xrm.Page.getControl(“bats_clientScript”).setDisabled(true);

Xrm.Page.getControl(“bats_clientScript”).setDisabled(false);

 

5. Set Access Level –

Xrm.Page.getAttribute(“bats_ClientCity”).setRequiredLevel(“none”);

Xrm.Page.getAttribute(“bats_ClientCity”).setRequiredLevel(“required”);

Xrm.Page.getAttribute(“bats_ClientCity”).setRequiredLevel(“recommended”);

6. Expand or Collapse a tab –

TabSectionHandling(“TAB_CONTRACT”, “collapsed”);

TabSectionHandling(“TAB_CONTRACT”, “expanded”);

 

7. GUID of an entity record-

Xrm.Page.data.entity.getId();

This function will remove curly braces from GUID

Xrm.Page.data.entity.getId().substring(1, 37);

 

I hope this helps to start with Dynamics Extension using JavaScript.

 

Happy Dynamics’ing !!!

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s