Friday, December 13, 2013

Creating Entity with an invalid parent.

When you create an email, letter or phone call through SDK (Plugin, Workflow or from your website or Silverlight application) you might get the error 'Creating Entity with an invalid parent. Entity: Email'

The reason behind this is your regarding object does not support activity association.

All you have to do is navigate the entity from Customisation and tick Activities in the 'Communication & Collaboration' section and publish the entity.

Hope this will help.

Tuesday, May 28, 2013

Moving the notes section to the top of the page

When you move the notes section to the top of the form and when the form is loaded, it automatically scrolls down and user has to manually scroll up to access the notes section.

If you want to see the notes section without scrolling please proceed the below steps.

1. If your have already added JQuery web resource to the form then just copy below code to a function and call at form- onload

$("#crmFormTabContainer").scrollTop(0); 


2. Or if you prefer the javascrips then just copy below code to a function and call at form- onload

document.getElementById('crmFormTabContainer').scrollTop = 0; 

Friday, February 22, 2013

Get System Users From Specific Team

Today I had a very simple request, which is to get System Users in a specific team. Since it was a very simple task I just Google and try to find a sample. I was amazed as there was no such exaample in the Net. So I had to write my own. Once it is done, I just thought to share it as it might be useful.
Here is the code.

1. First example is to get the System Users in a Team
2. Second example is to get System Users as ActivityParty that you might need to link with an Activity.

public List<SystemUser> GetTeamUsers(string teamName)
{
    return (from user in Context.CreateQuery<SystemUser>()
            join teamMembership in Context.CreateQuery<TeamMembership>() 
                 on user.SystemUserId.Value equals teamMembership.SystemUserId
            join team in Context.CreateQuery<Team>() on teamMembership.TeamId.Value equals team.TeamId.Value
            where team.Name == teamName
            select user
            ).ToList();
}

public List<ActivityParty> GetTeamUsersAsActivityParty(string teamName)
{
    return (from user in Context.CreateQuery<SystemUser>()
            join teamMembership in Context.CreateQuery<TeamMembership>() 
                 on user.SystemUserId.Value equals teamMembership.SystemUserId
            join team in Context.CreateQuery<Team>() on teamMembership.TeamId.Value equals team.TeamId.Value
            where team.Name == teamName
            select new ActivityParty
            {
                PartyId = new EntityReference { LogicalName = user.LogicalName, Id = user.SystemUserId.Value }
            }).ToList();
}