In CRM 2011, when you try to get the value of an OptionSet, you will always get an Integer value instead of the label value.
Below is the Helper method which is used to retrieve the label of the selected option set
public static string GetOptionSetValueLabel(IOrganizationService service, Entity entity, string attribute, OptionSetValue option)
{
string optionLabel = String.Empty;
RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
{
EntityLogicalName = entity.LogicalName,
LogicalName = attribute,
RetrieveAsIfPublished = true
};
RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)service.Execute(attributeRequest);
AttributeMetadata attrMetadata = (AttributeMetadata)attributeResponse.AttributeMetadata;
PicklistAttributeMetadata picklistMetadata = (PicklistAttributeMetadata)attrMetadata;
// For every status code value within all of our status codes values
// (all of the values in the drop down list)
foreach (OptionMetadata optionMeta in
picklistMetadata.OptionSet.Options)
{
// Check to see if our current value matches
if (optionMeta.Value == option.Value)
{
// If our numeric value matches, set the string to our status code
// label
optionLabel = optionMeta.Label.UserLocalizedLabel.Label;
}
}
return optionLabel;
}
Tuesday, October 18, 2011
Thursday, September 15, 2011
CRM 2011 Developer toolkit
CRM 2011 Developer toolkit is awesome!!!!! cuts down lot of development/deployment time.
Recommend everyone to use it.
P.S :- Still has some minor known issues as of August 2011
Recommend everyone to use it.
P.S :- Still has some minor known issues as of August 2011
Friday, August 19, 2011
Friday, July 29, 2011
Thursday, July 21, 2011
Page Large Result Sets with FetchXML
int fetchCount = 5000;
// Initialize the page number.
int pageNumber = 1;
string pagingCookie = null;
string fetchXml = Common.GetFetchXmlForComponentInfo(((EntityReference)entity.Attributes["neu_whatifmodelid"]).Id.ToString(), fiscalyear.ToString());
while (true)
{
string xml = Common.CreateXml(fetchXml, pagingCookie, pageNumber, fetchCount);
componentinfocollection = service.RetrieveMultiple(new FetchExpression(xml));
foreach (var c in componentinfocollection.Entities)
{
yearlyinfo.Add(
new ComponentYearlyInformation
{
ComponentId = c.Attributes.Contains("neu_componentid") ? ((EntityReference)c.Attributes["neu_componentid"]).Id : Guid.Empty,
name = c.Attributes.Contains("neu_name") ? (string)c.Attributes["neu_name"] : string.Empty,
YearlyExpenditure = c.Attributes.Contains("neu_yearlyexpenditure") ? (decimal)c.Attributes["neu_yearlyexpenditure"] : 0,
FullyFundedAmount = c.Attributes.Contains("neu_fullyfundedamount") ? (decimal)c.Attributes["neu_fullyfundedamount"] : 0
}
);
}
if (componentinfocollection.MoreRecords)
{
// Increment the page number to retrieve the next page.
pageNumber++;
pagingCookie = componentinfocollection.PagingCookie;
}
else
{
// If no more records in the result nodes, exit the loop.
break;
}
}
public static string CreateXml(string xml, string cookie, int page, int count)
{
StringReader stringReader = new StringReader(xml);
XmlTextReader reader = new XmlTextReader(stringReader);
// Load document
XmlDocument doc = new XmlDocument();
doc.Load(reader);
return CreateXml(doc, cookie, page, count);
}
public static string CreateXml(XmlDocument doc, string cookie, int page, int count)
{
XmlAttributeCollection attrs = doc.DocumentElement.Attributes;
if (cookie != null)
{
XmlAttribute pagingAttr = doc.CreateAttribute("paging-cookie");
pagingAttr.Value = cookie;
attrs.Append(pagingAttr);
}
XmlAttribute pageAttr = doc.CreateAttribute("page");
pageAttr.Value = System.Convert.ToString(page);
attrs.Append(pageAttr);
XmlAttribute countAttr = doc.CreateAttribute("count");
countAttr.Value = System.Convert.ToString(count);
attrs.Append(countAttr);
StringBuilder sb = new StringBuilder(1024);
StringWriter stringWriter = new StringWriter(sb);
XmlTextWriter writer = new XmlTextWriter(stringWriter);
doc.WriteTo(writer);
writer.Close();
return sb.ToString();
}
Reference : http://msdn.microsoft.com/en-us/library/gg309717.aspx
// Initialize the page number.
int pageNumber = 1;
string pagingCookie = null;
string fetchXml = Common.GetFetchXmlForComponentInfo(((EntityReference)entity.Attributes["neu_whatifmodelid"]).Id.ToString(), fiscalyear.ToString());
while (true)
{
string xml = Common.CreateXml(fetchXml, pagingCookie, pageNumber, fetchCount);
componentinfocollection = service.RetrieveMultiple(new FetchExpression(xml));
foreach (var c in componentinfocollection.Entities)
{
yearlyinfo.Add(
new ComponentYearlyInformation
{
ComponentId = c.Attributes.Contains("neu_componentid") ? ((EntityReference)c.Attributes["neu_componentid"]).Id : Guid.Empty,
name = c.Attributes.Contains("neu_name") ? (string)c.Attributes["neu_name"] : string.Empty,
YearlyExpenditure = c.Attributes.Contains("neu_yearlyexpenditure") ? (decimal)c.Attributes["neu_yearlyexpenditure"] : 0,
FullyFundedAmount = c.Attributes.Contains("neu_fullyfundedamount") ? (decimal)c.Attributes["neu_fullyfundedamount"] : 0
}
);
}
if (componentinfocollection.MoreRecords)
{
// Increment the page number to retrieve the next page.
pageNumber++;
pagingCookie = componentinfocollection.PagingCookie;
}
else
{
// If no more records in the result nodes, exit the loop.
break;
}
}
public static string CreateXml(string xml, string cookie, int page, int count)
{
StringReader stringReader = new StringReader(xml);
XmlTextReader reader = new XmlTextReader(stringReader);
// Load document
XmlDocument doc = new XmlDocument();
doc.Load(reader);
return CreateXml(doc, cookie, page, count);
}
public static string CreateXml(XmlDocument doc, string cookie, int page, int count)
{
XmlAttributeCollection attrs = doc.DocumentElement.Attributes;
if (cookie != null)
{
XmlAttribute pagingAttr = doc.CreateAttribute("paging-cookie");
pagingAttr.Value = cookie;
attrs.Append(pagingAttr);
}
XmlAttribute pageAttr = doc.CreateAttribute("page");
pageAttr.Value = System.Convert.ToString(page);
attrs.Append(pageAttr);
XmlAttribute countAttr = doc.CreateAttribute("count");
countAttr.Value = System.Convert.ToString(count);
attrs.Append(countAttr);
StringBuilder sb = new StringBuilder(1024);
StringWriter stringWriter = new StringWriter(sb);
XmlTextWriter writer = new XmlTextWriter(stringWriter);
doc.WriteTo(writer);
writer.Close();
return sb.ToString();
}
Reference : http://msdn.microsoft.com/en-us/library/gg309717.aspx
Tuesday, July 19, 2011
CRM 2011 plug-in tips and tricks (part 1) - Dev...
CRM 2011 plug-in tips and tricks (part 1) - Dev...: "There are a lot of examples of writing CRM 2011 plug-ins in the SDK , but none of them really describe the process of testing, troubleshooti..."
Wednesday, July 6, 2011
Configuring PPS in Sharepoint 2010
Good Blog post to refer for configuring PPS in SharePoint 2010
http://manojvnair.blogspot.com/2011/05/configure-performancepoint-services-in.html
http://manojvnair.blogspot.com/2011/05/configure-performancepoint-services-in.html
Subscribe to:
Posts (Atom)