Set optionset value for custom entity - dynamics-crm-online

I'd like to setting the optionset value for CRM with attribute type is PicklistAttributeMetadata:
//Executing Status
CreateAttributeRequest executingStatusAttributeRequest =
new CreateAttributeRequest
{
EntityName = customEntityName,
Attribute = new PicklistAttributeMetadata
{
SchemaName = prefix + "executingstatus",
DisplayName = new Label("Executing Status", 1033),
OptionSet = new OptionSetMetadata
{
IsGlobal = false,
OptionSetType = OptionSetType.Picklist,
Options = {
new OptionMetadata(new Label("Draft",1033),null),
new OptionMetadata(new Label("Executing",1033),null),
new OptionMetadata(new Label("Complete (No Errors)",1033),null),
new OptionMetadata(new Label("Complete (Errors)",1033),null)
}
}
}
};
CreateAttributeResponse executingStatusAttributeResponse =
(CreateAttributeResponse)_serviceProxy.Execute(
executingStatusAttributeRequest);
How to I set the 'dh_executingstatus' with value is 'Draft':
Entity dhEntity = new Entity(customEntityName);
dhEntity["dh_executingstatus"]=???

You'll want to give each option you create it's own unique integer value:
Options = {
new OptionMetadata(new Label("Draft",1033),1),
new OptionMetadata(new Label("Executing",1033),2),
new OptionMetadata(new Label("Complete (No Errors)",1033),3),
new OptionMetadata(new Label("Complete (Errors)",1033),4)
}
Then you'll need to publish the entity. Then, when working with a record, you can update the optionset value like this:
ent["dh_executingstatus"] = new OptionSetValue(2);

Related

SitecoreTypeCreationContext throws exception after GlassMapper upgrade

I'm getting exception:
Inner Exception: Object reference not set to an instance of an object.
at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext)
At InstantiateObject the creation context it's not null, the item it's populated.
If I add the typeOf(TItem) then it crashes there at TItem cast, if I comment then it crashes at instatinate.
I tried to remove ConstructorParameter but even on that case it's crashing
The code before upgrade:
var creationContext = new SitecoreTypeCreationContext
{
SitecoreService = sitecoreContext,
RequestedType = typeof(TItem),
ConstructorParameters = new object[0],
Item = item,
InferType = false,
IsLazy = true,
Parameters = new Dictionary<string, object>()
};
var result = sitecoreContext.InstantiateObject(creationContext) as TItem;
The code after upgrade
var creationContext = new SitecoreTypeCreationContext
{
SitecoreService = mvcContext.SitecoreService,
Item = item,
Parameters = new Dictionary<string, object>(),
Options = new GetOptions()
{
//Type = typeof(TItem),
InferType = false,
Lazy = LazyLoading.Enabled,
ConstructorParameters = new List<ConstructorParameter>()
}
};
var result= mvcContext.SitecoreService.InstantiateObject(creationContext) as TItem;
I missed maybe a configuration or RequestedType it's not equal Option.Type?

Modify "LocalizedName" for an Business-process-flow in Dynamics 365 (Version 9.0)

I need to unify the "display name" of an business-process-flow in our environment.
The standard BPF "Opportunity Sales Process", should be called "Opportunity Sales Process" regardless of the UI language of the use (e.g. "Vertriebsprozess Verkaufschance" is the "LocalizedName" for German users).
I have not found any way to change the "LocalizedName" value - the only option is see, is the direct update of the customizations.xml.
Is is possible to update the "LocalizedName" of an BPF via code?
IOrganizationService os; // todo - initialize
Its not clear what you're after :) If you're after updating entity metadata - that is doable:
var request = new RetrieveEntityRequest { LogicalName = "opportunitysalesprocess" };
var response = (RetrieveEntityResponse)os.Execute(request);
var label = response.EntityMetadata.DisplayName.LocalizedLabels
.First(l => l.LanguageCode == 1033);
label.Label = "Thats Not My Name";
os.Execute(new UpdateEntityRequest { Entity = response.EntityMetadata });
If you're after updating process name in grid of processes; it is:
var sec = new SetLocLabelsRequest
{
AttributeName = "name",
Labels = new LocalizedLabel[]
{
new LocalizedLabel
{
Label = "Thats not my name",
LanguageCode = 1033
}
},
EntityMoniker = new EntityReference("workflow",
new Guid("3E8EBEE6-A2BC-4451-9C5F-B146B085413A"))
};
var res = (SetLocLabelsResponse)os.Execute(sec);
Refer to
https://learn.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.setloclabelsrequest?view=dynamics-general-ce-9
https://learn.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.messages.updateentityrequest?view=dynamics-general-ce-9

Use IConfService to query object by Attributes

How do I query objects by attribute (instead of 'Filter Keys') using the Genesys Platform SDK?
Endpoint endpoint = new Endpoint("DEV", "the host", 12020);
endpoint.ServicePrincipalName = "the host/the principle";
_confServerProtocol = new ConfServerProtocol(endpoint);
_confServerProtocol.ClientApplicationType = (int)CfgAppType.CFGSCE;
_confServerProtocol.ClientName = "default";
_confServerProtocol.UserName = "the userid";
_confServerProtocol.Open();
IConfService confService = ConfServiceFactory.CreateConfService(_confServerProtocol);
CfgPersonQuery query = new CfgPersonQuery();
// Need to filter based on an Attribute Value (specifically externalID)
var foo = confService.RetrieveMultipleObjects<CfgPerson>(query);
This worked for me:
CfgXPathBasedQuery query = new CfgXPathBasedQuery(confService, CfgObjectType.CFGPerson, "CfgPerson[#externalID='the value']");
Use below:
Uri uri = new Uri("tcp://Host:Port");
Endpoint endpoint = new Endpoint(Guid.NewGuid().ToString(), uri);
ConfServerProtocol confProtocol = new ConfServerProtocol(endpoint);
confProtocol.ClientApplicationType = (int)CfgAppType.CFGSCE;
confProtocol.ClientName = "default";
confProtocol.UserName = "xxxxxx";
confProtocol.UserPassword = "xxxxxx";
//Channel Open
confProtocol.Open();
IConfService confService = ConfServiceFactory.CreateConfService(confProtocol);
CfgPersonQuery query = new CfgPersonQuery();
query.UserName = "AgentID";
CfgPerson person = confService.RetrieveObjects<CfgPerson>(query);
string ExtID = person.ExternalId;
Note: In this way, Filtering is not possible through ExternalId.

Bind List to GridviewComboboxcolumn in telerik radgrindview (winform)

I have a generic List like
List<return> returnlist
class return
{
public string returnid {get; set;
...
public List<string> Vouchernumbers
}
I bind the returnlist to the telerik radgridview.
How can i bind the voucherlist to the GridviewComboboxcolumn for each row ?
I have bind the voucherlist to the combobox after radgridview_complete_binding.
You need to create the grid with columns and data
You need to add the combobox column, initialize it.. Please check you need to have a dataeditor in here
Assign the string to datasource
comboColumn.DataSource = new String[] { "Test1", "Test2"};
You can bind the collections too:
Binding list BindingList<ComboBoxDataSourceObject> list = new BindingList<ComboBoxDataSourceObject>();
ComboBoxDataSourceObject object1 = new ComboBoxDataSourceObject();
object1.Id = 1;
object1.MyString = "Test 1";
list.Add(object1);
ComboBoxDataSourceObject object2 = new ComboBoxDataSourceObject();
object2.Id = 2;
object2.MyString = "Test 2";
list.Add(object2);
colboCol2.DataSource = list;
radGridView1.Columns.Add(colboCol2);
create radcombobox and set datasource and add it to rad grid
eg :
GridViewComboBoxColumn col = new GridViewComboBoxColumn();
col.DataSource = DAL.ActiveDb.GetList<SalesRep>().ToList().OrderBy(x => x.RepName).Select(x => new { Id = x.Id, x.RepName });
col.DropDownStyle = RadDropDownStyle.DropDown;
col.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
col.DisplayMember = "RepName";
col.ValueMember = "Id";
col.FieldName = "RepId";
col.HeaderText = "Rep Name";
col.Width = 200;
//var t = gridColInfo.Where(x => x.ColumnName.ToLower() == "repid").FirstOrDefault();
//if (t != null)
//{
// col.Width = t.ColumnWidth;
//}
this.radGridBillwiseOpening.Columns.Add(col);

Create a store from Code Behind and filter its content and bind it to Combobox Ext.Net 2.2

I am creating combobox in a component Column in a GridPanel from codebehind. There is requirement to create a store and filter its content according to some condition and bind it to the created combobox. Store is getting bind to combo but filter is not working. Please help me to get the proper solution for this. My code snippet is given below.
List<object> storeDataProductClass= new List<object>();
storeDataProductClass.Add(new { text = "Class0", value = "Class0", productIndex = 0});
storeDataProductClass.Add(new { text = "Class1", value = "Class1", productIndex = 1});
storeDataProductClass.Add(new { text = "Class2", value = "Class2", productIndex = 2});
storeDataProductClass.Add(new { text = "Class3", value = "Class3", productIndex = 3});
storeDataProductClass.Add(new { text = "Class4", value = "Class4", productIndex = 4});
Ext.Net.ComboBox cmbClass = new ComboBox();
cmbClass.ID = "cmbClass_" + i;
Model classModel = new Model();
classModel.Fields.Add(new ModelField("text", ModelFieldType.String));
classModel.Fields.Add(new ModelField("value", ModelFieldType.String));
classModel.Fields.Add(new ModelField("productIndex", ModelFieldType.Int));
Ext.Net.Store storeClass = new Ext.Net.Store();
storeClass.ID = "storeClass_" + i;
storeClass.AutoDataBind = true;
storeClass.Model.Add(classModel);
storeClass.DataSource = storeDataProductClass;
storeClass.DataBind();
storeClass.Filter("productIndex", i.ToString());
cmbClass.Store.Add(storeClass);
cmbClass.DisplayField = "text";
cmbClass.ValueField = "value";
compColumn.Component.Add(cmbClass);

Resources