CRM 2011: Get List of Solutions from given Publisher using C#

Hi Guys!

Here, I am presenting the method of getting all solutions from a specific publisher passed as a parameter from Microsoft Dynamics CRM 2011.

public static List<Solution> GetSolutionsList(IOrganizationService OrgService, Guid PublisherId)
{
    QueryExpression query = new QueryExpression()
    {
        EntityName = "solution",
        ColumnSet = new ColumnSet(true),
        Criteria = new FilterExpression()
    };

    query.Criteria.AddCondition(new ConditionExpression("publisherid", ConditionOperator.Equal, PublisherId));
    EntityCollection result = OrgService.RetrieveMultiple(query);
    List<Solution> SolutionList = new List<Solution>();

    foreach (var solution in result.Entities)
    {
        if (solution["uniquename"].ToString() != "System" && solution["uniquename"].ToString() != "Active" && solution["uniquename"].ToString() != "Basic" && solution["uniquename"].ToString() != "ActivityFeeds")
        {
            SolutionList.Add(
                new Solution()
                {
                    Id = (Guid)solution["solutionid"],
                    Name = solution["friendlyname"].ToString(),
                    PublisherId = ((EntityReference)solution["publisherid"]).Id,
                    UniqueName = solution["uniquename"].ToString()
                });
        }
    }

    return SolutionList;
}

And the Solution Class is defined as:

/// <summary>
/// Solution Class
/// </summary>
public class Solution
{
    /// <summary>
    /// Gets or sets the name.
    /// </summary>
    /// <value>
    /// The name of solution.
    /// </value>
    public string Name { get; set; }

    /// <summary>
    /// Gets or sets the id.
    /// </summary>
    /// <value>
    /// The id of solution.
    /// </value>
    public Guid Id { get; set; }

    /// <summary>
    /// Gets or sets the name of the unique.
    /// </summary>
    /// <value>
    /// The name of the unique.
    /// </value>
    public string UniqueName { get; set; }

    /// <summary>
    /// Gets or sets the publisher id.
    /// </summary>
    /// <value>
    /// The publisher id.
    /// </value>
    public Guid PublisherId { get; set; }
}

I want to specify that this code is used when CRM service proxy is not created in the project. You need to create an IOrganizationService object when you have connected to the CRM 2011 system and passing it to the method I have provided above.

Happy Programming!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s