I am trying to use the Metadata Web Service of Dynamics CRM to update the order of some picklist options using the UpdateAttributeRequest message. Though I get to change the attribute's DisplayName using the MergeLabels = false option, the picklist option values themselves seem immutable.
Have you tried the Order Option Request?
// Create the request.
OrderOptionRequest orderOptionRequest = new OrderOptionRequest();
// Set the properties for the request
orderOptionRequest.AttributeLogicalName = "address1_addresstypecode";
orderOptionRequest.EntityLogicalName = EntityName.contact.ToString();
// Set the order for the options.
orderOptionRequest.Values = new int[] { 4, 3, 2, 1 };
// Execute the request
OrderOptionResponse orderOptionResponse = (OrderOptionResponse)metadataService.Execute(orderOptionRequest);
Related
I want to update the fields like "cs_hv_additionnalparticularities", "cs_hv_smscope" and so on, but the function srv.Update(de);updates all the form records, I mean it triggers a workflow that I don't want it to happen.
here is my code:
// Retrieve the DynamicEntity that goes with target
RetrieveRequest retrieve = new RetrieveRequest();
retrieve.Target = target;
retrieve.ColumnSet = new AllColumns();
retrieve.ReturnDynamicEntities = true;
// Create a response reference and execute the retrieve request.
RetrieveResponse response1 = (RetrieveResponse)srv.Execute(retrieve);
DynamicEntity de = (DynamicEntity)response1.BusinessEntity;
if (opp.Properties.Contains("cs_hv_additionnalparticularities"))
de["cs_hv_additionnalparticularities"] = opp["cs_hv_additionnalparticularities"];
if (opp.Properties.Contains("cs_hv_smscope"))
de["cs_hv_smscope"] = opp["cs_hv_smscope"];
if (opp.Properties.Contains("cs_hv_ugscope"))
de["cs_hv_ugscope"] = opp["cs_hv_ugscope"];
if (opp.Properties.Contains("cs_hv_acdc"))
de["cs_hv_acdc"] = opp["cs_hv_acdc"];
if (opp.Properties.Contains("cs_hv_smmv"))
de["cs_hv_smmv"] = opp["cs_hv_smmv"];
if (opp.Properties.Contains("cs_hv_smhv"))
de["cs_hv_smhv"] = opp["cs_hv_smhv"];
if (opp.Properties.Contains("cs_hv_ughv"))
de["cs_hv_ughv"] = opp["cs_hv_ughv"];
if (opp.Properties.Contains("cs_hvid"))
de["cs_hvid"] = opp["cs_hvid"];
de["cs_generercable"] = new CrmBoolean(true);
srv.Update(de);
I don't want to use this function srv.Update(de); to update the fields.
Can somebody please give me the update function code that can do this work ??
If you don't want to update additional columns, just retrieve the specific columns (property ColumnSet) instead of the new AllColumns().
You can use only the update the record with the Update method, make sure that your workflow triggers only for the requested fields, and not for additional fields.
Consider the following method in a Web Api controller:
[Queryable(AllowedQueryOptions= AllowedQueryOptions.All)]
public override IQueryable<Mandate> Get()
{
return new List<Mandate>() { new Mandate() {
Id = 1,
PolicyNumber = "350000000",
OpenPositions = new List<OpenPosition>(){
new OpenPosition(){ Id = 1, Amount =2300 },
new OpenPosition(){ Id = 2, Amount =2100 }
}},
new Mandate() {
Id = 2,
PolicyNumber = "240000000" ,
OpenPositions = new List<OpenPosition>(){
new OpenPosition(){ Id = 3, Amount =2500 },
new OpenPosition(){ Id = 2, Amount =2100 }
}
} }.AsQueryable<Mandate>();
}
Here the list is built manually and if I browse to the following url:
http://localhost:52446/odata/Mandates?$filter=Id eq 1 it returns the correct item from the list.
Now obviously the list is more likely to be a database structure. Data would be retrieved using some ORM and returned to the Web API service.
I don't use Entity Framework (and I can't because of legacy systems).
How would I use Web API in this case? How would I translate the url parameters so that the filters are applied by the layer responsible of the data access?
Got it. You pointed me into the right direction with your LINQ provider. I found out I can do it easily with the ORM we are using (OpenAccess). More info here :http://docs.telerik.com/data-access/developers-guide/using-web-services/asp.net-web-api/developer-guide-wcfservices-web-api-expose-oacontext
How to get list of data items list from CRM Metadata Source in code behind?
I have a CRm Metadata Source like
<crm:CrmMetadataDataSource ID="dsquestionOptionset" runat="server" EntityName="contact"
AttributeName="securityquestion"/>
in the html.
I would like to get list of data items in the code behind from the datasource.
"securityquestion" is an intger value and this is linked to an option set.
I tried like
var listOfItems=dsquestionOptionset.Items;
But not possible
Any help is appreciated
Vinu
You'll want to query the Metadata. An example (from here: http://msdn.microsoft.com/en-us/library/gg509035.aspx) would be something like:
RetrieveAttributeRequest retrieveAttributeRequest =
new RetrieveAttributeRequest
{
EntityLogicalName = Contact.EntityLogicalName,
LogicalName = "new_picklist",
RetrieveAsIfPublished = true
};
// Execute the request.
RetrieveAttributeResponse retrieveAttributeResponse =
(RetrieveAttributeResponse)_serviceProxy.Execute(
retrieveAttributeRequest);
// Access the retrieved attribute.
PicklistAttributeMetadata retrievedPicklistAttributeMetadata =
(PicklistAttributeMetadata)
retrieveAttributeResponse.AttributeMetadata;
// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =
retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
I'm using CRM 2011, and attempting to update the OwnerId of contact using this code:
var crmContext = new CustomCrmContext(service);
var contact = crmContext.Contact.FirstOrDefault(c=>c.Id == id);
contact.OwnerId.Id= newOwnerId;
crmContext.UpdateObject(contact);
crmContext.SaveChanges();
I don't get any errors, however, the ownerId never updates in the database. I am able to update other attributes, but I'm just wondering if maybe the OwnerId is special and you have to use OrganizationRequest("Assign")? If so, where is this documented so I know what other attributes I cannot update?
The owner of a record cannot be modified with an update. You have to send a AssignRequest instead.
// Create the Request Object and Set the Request Object's Properties
var request = new AssignRequest
{
Assignee = new EntityReference(SystemUser.EntityLogicalName, _newOwnerId),
Target = new EntityReference(Account.EntityLogicalName, _accountId)
};
// Execute the Request
_service.Execute(request);
I want to query the values from the different Picklist in Opportunity. I don't want to query the actual Opportunity, just the values from the Picklist. So if I have a Picklist called Source and it has the values of 1, 2, 3, 4, 5. I want to query the picklist and get back those values. Is this possible? If so, how in the world do you do it? Thanks!
Figured it out:
RetrieveAttributeRequest request = new RetrieveAttributeRequest();
request.EntityLogicalName = "opportunity";
request.LogicalName = "new_businessunit";
RetrieveAttributeResponse response = (RetrieveAttributeResponse)orgService.Execute(request);
PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;
int? businessid = null;
foreach (OptionMetadata option in picklist.OptionSet.Options)
{
string businesslabel = option.Label.UserLocalizedLabel.Label.ToString();
}