Sample code to check if User is a member of a team C# CRM 2011/2013/2015


Sharing sample code to check if a user belongs to a team or not

public static bool IsTeamMember(Guid teamID, Guid userID, IOrganizationService service)
QueryExpression query = new QueryExpression("team");
query.ColumnSet = new ColumnSet(true);
query.Criteria.AddCondition(new ConditionExpression("teamid", ConditionOperator.Equal, teamID));
LinkEntity link = query.AddLink("teammembership", "teamid", "teamid");
link.LinkCriteria.AddCondition(new ConditionExpression("systemuserid", ConditionOperator.Equal, userID));
var results = service.RetrieveMultiple(query);

if (results.Entities.Count > 0)
return true;
return false;

Hope it helps.

Sample code to read XML Data from Web Resource in Plugin in CRM 2011/2013/2015


We recently had a requirement to read xml data stored in a particular web resource in plugin.

Sharing the sample code

public static Dictionary<string, string> GetMarketClusterAndMarketSegment(string webresourceName, string buildingTypeValue, IOrganizationService organizationService)
Dictionary<string, string> dictionaryMarket = new Dictionary<string, string>();

// tk_et_oppline_marketingfilterpicklists
// create request to retrieve Webresource
ColumnSet cols = new ColumnSet();
QueryByAttribute requestWebResource = new QueryByAttribute
EntityName = "webresource",
ColumnSet = cols

Entity webResourceEntity = null;
EntityCollection webResourceEntityCollection = organizationService.RetrieveMultiple(requestWebResource);

if (webResourceEntityCollection.Entities.Count > 0)
webResourceEntity = webResourceEntityCollection.Entities[0];
byte[] binary = Convert.FromBase64String(webResourceEntity.Attributes["content"].ToString());
string resourceContent = System.Text.Encoding.UTF8.GetString(binary);
string byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
if (resourceContent.StartsWith(byteOrderMarkUtf8))
resourceContent = resourceContent.Remove(0, byteOrderMarkUtf8.Length);

XDocument xmlDocument = XDocument.Parse(resourceContent);

var marketSegment = from t in xmlDocument.Descendants("ParentField").ElementAt(1).Descendants("ShowOption")
where t.Attribute("value").Value.Equals(buildingTypeValue)
select new
marketSegmentValue = t.Parent.Attribute("value").Value,
marketSegmentLabel = t.Parent.Attribute("label").Value

foreach (var v in marketSegment)
dictionaryMarket.Add("marketsegment", v.marketSegmentValue);
var marketCluster = from t in xmlDocument.Descendants("ParentField").ElementAt(0).Descendants("ShowOption")
where t.Attribute("value").Value.Equals(v.marketSegmentValue)
select new
marketClusterValue = t.Parent.Attribute("value").Value,
marketClusterLabel = t.Parent.Attribute("label").Value

foreach (var m in marketCluster)
dictionaryMarket.Add("marketcluster", m.marketClusterValue);

return dictionaryMarket;

Hope it helps..

You cannot send email as the selected user. The selected user has not allowed this or you do not have sufficient privileges to do so. Contact your system administrator for assistance. Error in CRM 2013/2015


Was getting the below error in one of the custom workflow activity we were using for sending email.

To fix the issue,

Login to CRM with the user selected as From.

Open Set Personal Options box

And check the check box “Allow other Microsoft Dynamics CRM users to send email on your behalf”

Hope it helps..

Dynamics CRM 2015 – Interact with the Business Process Flow controls in the form


Originally posted on ADISYS Technology Corner:

With Microsoft Dynamics CRM 2015, the namespace provides events, methods, and objects to interact with the business process flow data in a form.

This sample demonstrates how to switch to different stage using the new methods.

Followings are the API used in the sample code:

getActiveProcess() – retrieve information about the active process

setActiveProcess()- Set different process as the active process.

getActiveStage()- retrieve information about the active stage

setActiveStage() – set a different stage as the active stage.

getActivePath() – get a collection of stages currently in the active path with methods to interact with the stages displayed in the business process flow control.

addOnStageChange(),removeOnStageChange() – add or remove event handlers for the business process flow control.

addOnStageSelected() – add a function as an event handler for the OnStageSelected event so that it will be called when a…

View original 453 more words

CRM 2011 Parental Relationship Behaviour (the Reparent action) in Practise


Originally posted on WOODSWORKBLOG:

Parental relationships in Mscrm do a couple of things, in this post I’m going to focus on the reparent action.

(As a side note, reparent isn’t exclusively used in the parental behaviour, but is where it is most commonly used).

View original 333 more words