Wednesday, May 18, 2011

JavaScript - MS CRM 2011

Dynamics CRM 2011: Passing Selected Record Guids to JS function

Use the below Xml Script to pass Selected Grid record Guids to JScript function called from Ribbon button

The Above CRM parameter "SelectedControlSelectedItemIds" is accessible in function "Clone"

function Clone(SelectedControlSelectedItemIds)

{

alert(SelectedControlSelectedItemIds);

//..

}


//Get Entity Name
function GetEntityName() {
return Xrm.Page.data.entity.getEntityName();
}

//Get User Id
function GetUserId() {
return Xrm.Page.context.getUserId()
}

//Get User Roles
function GetUserRole() {
return Xrm.Page.context.getUserRoles();
}
//Hide Tab
function HideTab(tabName){
var Tab = Xrm.Page.ui.tabs.get(tabName);
if (Tab != null){
Tab.setVisible(false);
}
}

//Display Tab
function DisplayTab(tabName) {
var Tab = Xrm.Page.ui.tabs.get(tabName);
if (Tab != null) {
Tab.setVisible(true);
}
}

//Hide Section
function HideSection(tabName, sectionName){
var Tab = Xrm.Page.ui.tabs.get(tabName);
if (Tab != null){
var Section = Tab.sections.get(sectionName);
if (Section != null) {
Section.setVisible(false);
}
}
}

//Display Section
function DisplaySection(tabName, sectionName) {
var Tab = Xrm.Page.ui.tabs.get(tabName);
if (Tab != null) {
var Section = Tab.sections.get(sectionName);
if (Section != null) {
Section.setVisible(true);
}
}
}

//Disable the attributes in a Section
function DisableAttributesSection(tabName, sectionName) {
var Tab = Xrm.Page.ui.tabs.get(tabName);
if (Tab != null) {
var Section = Tab.sections.get(sectionName);
if (Section != null) {
var iCount = Section.controls.getLength();
if (iCount > 0) {
for (var iLoop = 0; iLoop < iCount; iLoop++) {
Section.controls.get(iLoop).setDisabled(true);
}
}
}
}
}

//Enable the attributes in a Section
function EnableAttributesSection(tabName, sectionName) {
var Tab = Xrm.Page.ui.tabs.get(tabName);
if (Tab != null) {
var Section = Tab.sections.get(sectionName);
if (Section != null) {
var iCount = Section.controls.getLength();
if (iCount > 0) {
for (var iLoop = 0; iLoop < iCount; iLoop++) {
Section.controls.get(iLoop).setDisabled(false);
}
}
}
}
}

//Disable Attribute
function DisableAttribute(attributeName) {
var Attribute = Xrm.Page.data.entity.attributes.get(attributeName);
if (Attribute != null) {
Attribute.controls.get(0).setDisabled(true);
}
}

//Enable Attribute
function EnableAttribute(attributeName) {
var Attribute = Xrm.Page.data.entity.attributes.get(attributeName);
if (Attribute != null) {
Attribute.controls.get(0).setDisabled(false);
}
}

//Hide Attribute
function HideAttribute(attributeName) {
var Attribute = Xrm.Page.data.entity.attributes.get(attributeName);
if (Attribute != null) {
Attribute.controls.get(0).setVisible(false);
}
}

//Display Attribute
function DisplayAttribute(attributeName) {
var Attribute = Xrm.Page.data.entity.attributes.get(attributeName);
if (Attribute != null) {
Attribute.controls.get(0).setVisible(true);
}
}


//Set Values
function SetValues(attributeName, value, name, entityName) {
var Attribute = Xrm.Page.data.entity.attributes.get(attributeName);
if (Attribute != null) {
var type = Attribute.getAttributeType();
switch (type) {
case "boolean":
Attribute.setValue(value);
Attribute.setSubmitMode("always");
break;
case "decimal":
Attribute.setValue(parseFloat(value));
Attribute.setSubmitMode("always");
break;
case "double":
Attribute.setValue(parseFloat(value));
Attribute.setSubmitMode("always");
break;
case "integer":
Attribute.setValue(parseInt(value));
Attribute.setSubmitMode("always");
break;
case "money":
Attribute.setValue(parseFloat(value));
Attribute.setSubmitMode("always");
break;
case "optionset":
Attribute.setValue(parseInt(value));
Attribute.setSubmitMode("always");
break;
case "memo":
Attribute.setValue(value);
Attribute.setSubmitMode("always");
break;
case "string":
Attribute.setValue(value);
Attribute.setSubmitMode("always");
break;
case "datetime":
Attribute.setValue(value);
Attribute.setSubmitMode("always");
break;
case "lookup":
var values = new Array();
values[0] = new Object();
values[0].id = value;
values[0].name = name;
values[0].entityType = entityName;
Attribute.setValue(values);
Attribute.setSubmitMode("always");
break;
}
}
}

//Get Values
function GetValues(attributeName) {
var Attribute = Xrm.Page.data.entity.attributes.get(attributeName);
if (Attribute != null) {
var type = Attribute.getAttributeType();
var value = Attribute.getValue();
if (value != null) {
switch (type) {
case "boolean":
return value;
break;
case "decimal":
return value;
break;
case "double":
return value;
break;
case "integer":
return value;
break;
case "money":
return value;
break;
case "optionset":
return value;
break;
case "memo":
return value;
break;
case "string":
return value;
break;
case "datetime":
return value.toString();
break;
case "lookup":
return value[0].id.toString();
break;
}
}
}
}

1 comment:


  1. Its so nice Blog Sir. Your all Blogs always based on all basic concepts which anyone can understand so easily. Pleasure to read your Blogs Sir.
    For more Information Visit Our Website Web Designing Course in Rohini

    ReplyDelete