Custom Entity creation through C#

CreateEntityRequest createrequest = new CreateEntityRequest
 {
 Entity = new EntityMetadata
 {
 SchemaName = "new_rakesh",
 DisplayName = new Label("rakeshs", 1033),
 DisplayCollectionName = new Label("rakeshs", 1033),
 Description = new Label("An entity to store information custom customer bank accounts", 1033),
 OwnershipType = OwnershipTypes.UserOwned,
 IsActivity = false,
 },
 PrimaryAttribute = new StringAttributeMetadata
 {
 SchemaName = "new_names",
 RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
 MaxLength = 100,
 FormatName = StringFormatName.Text,
 DisplayName = new Label("Names", 1033),
 Description = new Label("The primary attribute for the Custom entity.", 1033)
 },
 };
 service.Execute(createrequest);
Advertisements

Dependent Optionset/ Pick List

Dependent Optionset/ Pick List

In a recent scenario, I was asked to create a dependent Pick-list/ Option set list where the options of Second Pick-list are dependent on the Value of the First one. By default there is no such option in Dynamics CRM but I came up with a solution from SDK.

Optionsets are-

  1. category- Gold, Silver, Diamond

2.Subcategory-

gold1,gold2,gold3,gold4,silver1,silver2,silver3,silver4,diamond1,diamond2,diamod4

var gold=1;
var silver =2;
var diamond =3;
var subcategory ="new_subcategory",
 subcategorygold=[1,2,3,4],
 subcategorysilver=[5,6,7,8],
 subcategorydiamond=[9,10,11,12];


function optionset()
{
 debugger;
 var categoryattribute = Xrm.Page.getAttribute("new_category").getValue();
 var subcategoryattr= Xrm.Page.getAttribute(subcategory);
 var subcategorycontrol= Xrm.Page.getControl(subcategory);
 switch(categoryattribute)
 {
 case gold :
 addoptionset(subcategoryattr,subcategorygold,subcategorycontrol)
 break;
 case silver:
 addoptionset(subcategoryattr,subcategorysilver,subcategorycontrol)
 break;
 case diamond:
 addoptionset(subcategoryattr,subcategorydiamond,subcategorycontrol)
 break;
 }
 
}

function addoptionset(attribute,subcat,control)
{
 control.clearOptions();
 subcat.forEach(function(currentoption, Index)
 {
 var option= attribute.getOption(currentoption);
 control.addOption(option,Index);
 });
 
}