Nice post !
Seriously. Where have the radio buttons gone for “Two Options” type bit fields in CRM 2013?!
View original post 307 more words
Nice post !
Seriously. Where have the radio buttons gone for “Two Options” type bit fields in CRM 2013?!
View original post 307 more words
Hi,
We were using the below function in CRM 2011 for disabling all the fields in the form.
function makeAllAttributesReadOnly() {
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes) {
var myattribute = Xrm.Page.data.entity.attributes.get(attributes[i].getName());
var myname = myattribute.getName();
Xrm.Page.getControl(myname).setDisabled(true);
}
}
However this function in CRM 2013 was giving us setDisabled field is undefined JavaScript error.
As it turned out it was because of the StateCode (Status) field in CRM 2013.

Modifying the above code to leave this particular field resolved the issue.
function makeAllAttributesReadOnly() {
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes) {
var myattribute = Xrm.Page.data.entity.attributes.get(attributes[i].getName());
var myname = myattribute.getName();
if(myname == "statecode")
{
return;
}
Xrm.Page.getControl(myname).setDisabled(true);
}
}
Hope it helps.
Recently we had a requirement to add checkboxes in our mail merge templates. There are two options of adding checkboxes one is adding them as a symbol if we want user to check them after taking print out or if we want them to be clickable inside the word document itself using content control.
Check this helpful post
Hope it helps.
Just sharing the helper class we use for writing Unit Test for Plugin using Microsoft Fakes
Sample Code for Plugin
</pre>
public class PluginClass: IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
// Everytime a lead record is created
// Create a corresponding contact record
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)
serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService orgService = serviceFactory.CreateOrganizationService(context.UserId);
if (entity.LogicalName == "lead")
{
Entity contactEntity = new Entity("contact");
contactEntity.Attributes["lastname"] = entity.Attributes["subject"];
orgService.Create(contactEntity);
}
}
}
}
Sample Code for Unit Test Class
</pre>
[TestClass]
public class UnitTest1
{
[TestMethod]
public void UnitTestMethod()
{
var serviceProvider = new StubIServiceProvider();
var pluginContext = new StubIPluginExecutionContext();
var organizationService = new StubIOrganizationService();
// Mole the basic Plugin objects
Helper.FakePluginVariables(serviceProvider, pluginContext, organizationService, 40, "Create");
// set the mole of entity
var entityAttributes = new Dictionary<string, object>();
entityAttributes.Add("subject", "Test Subject");
Entity leadEntity = Helper.FakeEntity("lead", entityAttributes, pluginContext);
// set the entity in the parameter collection
var parameterAttributes = new Dictionary<string, object>();
parameterAttributes.Add("Target", leadEntity);
Helper.FakePluginInputParameters(pluginContext, parameterAttributes);
organizationService.CreateEntity = (p1) => { return Guid.NewGuid(); };
var postCreateLead = new Class1();
postCreateLead.Execute(serviceProvider);
}
}
Helper class
</pre>
/// <summary>
/// Helper class for Fakes
/// </summary>
public static class Helper
{
/// <summary>
/// Fakes the plugin variables.
/// </summary>
/// <param name="serviceProvider">The service provider.</param>
/// <param name="pluginContext">The plugin context.</param>
/// <param name="organizationService">The organization service.</param>
/// <param name="stageNumber">The stage number.</param>
/// <param name="messageName">Name of the message.</param>
public static void FakePluginVariables(
StubIServiceProvider serviceProvider,
StubIPluginExecutionContext pluginContext,
StubIOrganizationService organizationService,
int stageNumber,
string messageName)
{
var serviceFactory = new StubIOrganizationServiceFactory();
var tracingService = new StubITracingService();
if (serviceProvider != null)
{
serviceProvider.GetServiceType = type =>
{
if (type == typeof(IPluginExecutionContext))
{
return pluginContext;
}
else if (type == typeof(ITracingService))
{
return tracingService;
}
else if (type == typeof(IOrganizationServiceFactory))
{
return serviceFactory;
}
return null;
};
}
pluginContext.DepthGet = () => 1;
pluginContext.UserIdGet = () => new Guid();
pluginContext.MessageNameGet = () => messageName;
pluginContext.StageGet = () => stageNumber;
pluginContext.InitiatingUserIdGet = () => new Guid();
pluginContext.CorrelationIdGet = () => new Guid();
pluginContext.PrimaryEntityIdGet = Guid.NewGuid;
serviceFactory.CreateOrganizationServiceNullableOfGuid = t1 => organizationService;
tracingService.TraceStringObjectArray = Trace;
}
/// <summary>
/// Sets the Fakes for the Entity
/// </summary>
/// <param name="entityName">The LogicalName of the entity</param>
/// <param name="attributeValues">The attributes of the entity</param>
/// <param name="context">Object of type SIPluginExecutionContext</param>
/// <returns>Object of type Entity</returns>
public static Entity FakeEntity(string entityName, Dictionary<string, object> attributeValues, StubIPluginExecutionContext context)
{
var entity = new Entity(entityName);
entity.Attributes = new AttributeCollection();
if (attributeValues != null)
{
foreach (string key in attributeValues.Keys)
{
entity.Attributes.Add(key, attributeValues[key]);
}
}
if (context != null)
{
context.PrimaryEntityNameGet = () => entityName;
}
entity.Id = Guid.NewGuid();
return entity;
}
/// <summary>
/// Fakes the PluginContext.InputParameters
/// </summary>
/// <param name="context">the mole of the IPluginExecutionContext</param>
/// <param name="inputParameterCollection">Object of type System.Dictionary</param>
public static void FakePluginInputParameters(StubIPluginExecutionContext context, Dictionary<string, object> inputParameterCollection)
{
if (inputParameterCollection != null)
{
var parameterCollection = new ParameterCollection();
foreach (var key in inputParameterCollection.Keys)
{
parameterCollection.Add(key, inputParameterCollection[key]);
}
if (context != null)
{
context.InputParametersGet = () => parameterCollection;
}
}
}
/// <summary>
/// Detour method for the CRM Trace method
/// </summary>
/// <param name="content">the message to be traced</param>
/// <param name="value">Object of type object []</param>
public static void Trace(string content, params object[] value)
{
}
}
// Update
organizationService.UpdateEntity = (p) =>
{
};
// Execute
organizationService.ExecuteOrganizationRequest = orgReq =>
{
return new OrganizationResponse();
};
// Retrieve
organizationService.RetrieveStringGuidColumnSet = (p1, p2, p3) =>
{
Entity entity = null;
if (p1 == entity1.EntityLogicalName)
{
entity = new Entity(entity1.EntityLogicalName);
entity.Id = Guid.NewGuid();
entity.Attributes["new_category"] = new OptionSetValue(12345);
entity.FormattedValues["new_category"] = "home";
}
else if (p1 == entity2.EntityLogicalName)
{
entity = new Entity(entity2.EntityLogicalName);
entity.Id = Guid.NewGuid();
entity.Attributes["new_moneyattr"] = new Money(100.0M);
}
return entity;
};
//RetrieveMultiple
organizationService.RetrieveMultipleQueryBase = delegate(QueryBase query)
{
var collection = new EntityCollection();
Entity entity;
if (query is FetchExpression)
{
entity = new Entity(entity.EntityLogicalName);
entity.Attributes = new AttributeCollection();
entity.Attributes.Add("attr", "value");
collection.Entities.Add(entity);
}
return collection;
};
// PreImage
pluginContext.PreEntityImagesGet = () =>
{
EntityImageCollection entityImgColl = new EntityImageCollection();
Entity preImageEntity = new Entity(enitity1.EntityLogicalName);
preImageEntity.Attributes.Add("new_id", new EntityReference(entity2.EntityLogicalName, Guid.NewGuid()));
preImageEntity.Attributes.Add("new_bool", false);
KeyValuePair<string, Entity> kvp = new KeyValuePair<string, Entity>("PreImageAI", preImageEntity);
entityImgColl.Add(kvp);
return entityImgColl;
};
Hope it helps
Hi,
Recently we had a requirement to disable Add New and Edit button of a sub grid record based on parent record’s attribute value.
For this we first need to add a new EnableRule and pass the id of the parent record to a custom function that will use this value to get value of the form and pass true and false accordingly.
FirstPrimaryItemId CRMParameter will pass the id of the parent record.
<EnableRule Id="new.new_fcm_child.EnableRule2.EnableRule"> <CustomRule FunctionName="DisableButton" Library="$webresource:new_myScript" Default="true"> <CrmParameter Value="FirstPrimaryItemId" /> </CustomRule> </EnableRule>
Adding this EnableRule to existing CommandDefinitions
<RibbonDiffXml> <CustomActions /> <Templates> <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates> </Templates> <CommandDefinitions> <CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandard"> <EnableRules> <EnableRule Id="Mscrm.AppendToPrimary" /> <EnableRule Id="Mscrm.EntityFormIsEnabled" /> <EnableRule Id="new.new_fcm_child.EnableRule2.EnableRule" /> </EnableRules> <DisplayRules> <DisplayRule Id="Mscrm.ShowForOneToManyGrids" /> <DisplayRule Id="Mscrm.AppendToPrimary" /> <DisplayRule Id="Mscrm.CreateSelectedEntityPermission" /> <DisplayRule Id="Mscrm.AppendSelected" /> <DisplayRule Id="Mscrm.HideAddNewForChildEntities" /> </DisplayRules> <Actions> <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addNewFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js"> <CrmParameter Value="SelectedEntityTypeCode" /> <CrmParameter Value="PrimaryEntityTypeCode" /> <CrmParameter Value="FirstPrimaryItemId" /> <CrmParameter Value="PrimaryControl" /> </JavaScriptFunction> </Actions> </CommandDefinition> <CommandDefinition Id="Mscrm.EditSelectedRecord"> <EnableRules> <EnableRule Id="Mscrm.CheckBulkEditSupportForEntity" /> <EnableRule Id="Mscrm.VisualizationPaneNotMaximized" /> <EnableRule Id="new.new_fcm_child.EnableRule2.EnableRule" /> </EnableRules> <DisplayRules> <DisplayRule Id="Mscrm.BulkEditPrivilege" /> <DisplayRule Id="Mscrm.WriteSelectedEntityPermission" /> </DisplayRules> <Actions> <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.bulkEdit" Library="/_static/_common/scripts/RibbonActions.js"> <CrmParameter Value="SelectedControl" /> <CrmParameter Value="SelectedControlSelectedItemReferences" /> <CrmParameter Value="SelectedEntityTypeCode" /> </JavaScriptFunction> </Actions> </CommandDefinition> </CommandDefinitions> <RuleDefinitions> <TabDisplayRules /> <DisplayRules> <DisplayRule Id="Mscrm.AppendSelected"> <EntityPrivilegeRule PrivilegeType="Append" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" /> </DisplayRule> <DisplayRule Id="Mscrm.AppendToPrimary"> <EntityPrivilegeRule PrivilegeType="AppendTo" PrivilegeDepth="Basic" AppliesTo="PrimaryEntity" /> </DisplayRule> <DisplayRule Id="Mscrm.BulkEditPrivilege"> <MiscellaneousPrivilegeRule PrivilegeName="BulkEdit" /> </DisplayRule> <DisplayRule Id="Mscrm.CreateSelectedEntityPermission"> <EntityPrivilegeRule PrivilegeType="Create" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" /> </DisplayRule> <DisplayRule Id="Mscrm.HideAddNewForChildEntities"> <OrRule> <Or> <EntityPropertyRule AppliesTo="SelectedEntity" PropertyName="IsChildEntity" PropertyValue="false" /> </Or> <Or> <RelationshipTypeRule AppliesTo="SelectedEntity" AllowCustomRelationship="false" /> </Or> </OrRule> </DisplayRule> <DisplayRule Id="Mscrm.ShowForOneToManyGrids"> <RelationshipTypeRule AppliesTo="SelectedEntity" RelationshipType="OneToMany" /> </DisplayRule> <DisplayRule Id="Mscrm.WriteSelectedEntityPermission"> <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" /> </DisplayRule> </DisplayRules> <EnableRules> <EnableRule Id="new.new_fcm_child.EnableRule2.EnableRule"> <CustomRule FunctionName="DisableButton" Library="$webresource:new_Service_Request_Script" Default="true"> <CrmParameter Value="FirstPrimaryItemId" /> </CustomRule> </EnableRule> <EnableRule Id="Mscrm.AppendToPrimary"> <RecordPrivilegeRule PrivilegeType="AppendTo" AppliesTo="PrimaryEntity" /> </EnableRule> <EnableRule Id="Mscrm.CheckBulkEditSupportForEntity"> <OrRule> <Or> <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" Maximum="1" /> </Or> <Or> <SelectionCountRule AppliesTo="SelectedEntity" Minimum="2" /> <CustomRule FunctionName="Mscrm.RibbonActions.isBulkEditEnabledForEntity" Library="/_static/_common/scripts/RibbonActions.js"> <CrmParameter Value="SelectedEntityTypeCode" /> </CustomRule> </Or> </OrRule> </EnableRule> <EnableRule Id="Mscrm.EntityFormIsEnabled"> <FormStateRule State="Disabled" InvertResult="true" /> </EnableRule> <EnableRule Id="Mscrm.VisualizationPaneNotMaximized"> <CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js"> <CrmParameter Value="SelectedControl" /> </CustomRule> </EnableRule> </EnableRules> </RuleDefinitions> <LocLabels /> </RibbonDiffXml>
The JavaScript code
// function to disable related record
function DisableButton(id) {
//CRM Server Url:
var result = true;
var serverUrl = Xrm.Page.context.getServerUrl();
// OData Call to get the data
var ServiceRequestQuery = "new_CustomEntitySet?$select=attr1,attr2&$filter=attrId eq guid'" + id + "'";
var ServiceRequestUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/" + ServiceRequestQuery;
// make synchronous call
var ServiceRequest= syncODataCall(ServiceRequestUrl);
// get the option set value
if (ServiceRequest[0].attr1 != null && ServiceRequest[0].attr2 != null) {
var attr1Value = ServiceRequest[0].attr1.Value;
var attr2Value = ServiceRequest[0].attr2 .Value;
if (attr1Value != "863600004" && attr2Value == "279640002") {
result = false;
}
else {
result = true;
}
}
return result;
}
// function to make synchronous oData call
function syncODataCall(odataSelect) {
var request = new XMLHttpRequest();
request.open("GET", odataSelect, false);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Content-Type", "application/json; charset=utf-8");
request.send();
var objJQuery = JSON.parse(request.responseText);
return objJQuery.d.results;
}
Hope it helps
Hi,
We recently faced this issue in one of our web resources (html). If we are trying to move the bottom scrollbar in the form, we get the below error in jscrpt.

This issue only occurred IE 8 and Update Rollup 15.
It worked properly in IE 9, 10, 11 and Update Rollup 15.
In one of the forums it was suggested that this issue will not occur if we only have UR 12. We tested it and found out that it did work properly in IE 8 with only Update Rollup 12.
http://community.dynamics.com/crm/f/117/p/119766/250458.aspx
Bye.