Create a CRM team and set the business department of the team

Source: Internet
Author: User

Using system;
Using Microsoft. xrm. SDK;
Using Microsoft. CRM. SDK. messages;
Using Microsoft. xrm. SDK. messages;

/// <Summary>
/// Team
/// </Summary>
Public class teamhelper
{
Public static readonly string entityname = "team ";
Public guid teamid = guid. empty;

/// <Summary>
/// Create a team
/// </Summary>
/// <Param name = "service"> service </param>
Public void create (iorganizationservice Service)
{
Entity en = new entity () {logicalname = entityname };
En ["name"] = "Software Development Team ";
Teamid = service. Create (en );
}

/// <Summary>
/// Set the business department of the team
/// </Summary>
/// <Param name = "service"> service </param>
/// <Param name = "unitid"> business department ID </param>
Public void setparentunit (iorganizationservice service, guid unitid)
{
Setparentteamrequest request = new setparentteamrequest ();
// Business department ID
Request. businessid = unitid;
// Team ID
Request. teamid = teamid;
Service. Execute (request );
}

/// <Summary>
/// Modify the team
/// </Summary>
/// <Param name = "service"> service </param>
Public void Update (iorganizationservice Service)
{
Entity en = new entity () {logicalname = entityname, id = teamid };
En ["name"] = "Software Development Team ";
Service. Update (en );
}

/// <Summary>
/// Add members to the team
/// </Summary>
/// <Param name = "service"> service </param>
/// <Param name = "userarrays"> User ID array </param>
Public void adduser (iorganizationservice service, guid [] userarrays)
{
Addmembersteamrequest request = new addmembersteamrequest ();
// Team
Request. teamid = teamid;
// User ID Array
Request. memberids = userarrays;
Service. Execute (request );
}

/// <Summary>
/// Remove a member from the team
/// </Summary>
/// <Param name = "service"> service </param>
/// <Param name = "userarrays"> User ID array </param>
Public void removeuser (iorganizationservice service, guid [] userarrays)
{
Removemembersteamrequest request = new removemembersteamrequest ();
// Team
Request. teamid = teamid;
// User ID Array
Request. memberids = userarrays;
Service. Execute (request );
}

/// <Summary>
/// Query team Permissions
/// </Summary>
/// <Param name = "service"> service </param>
Public void searchteamrole (iorganizationservice Service)
{
Retrieveteamprivilegesrequest request = new retrieveteamprivilegesrequest ();
// Team
Request. teamid = teamid;
Retrieveteamprivilegesresponse response = (retrieveteamprivilegesresponse) service. Execute (request );
If (response. roleprivileges! = NULL)
{
Roleprivilege [] array = response. roleprivileges;
}
}

/// <Summary>
/// Add and remove security roles
/// </Summary>
/// <Param name = "service"> service </param>
/// <Param name = "roleid"> security role id </param>
Public void addandremoverole (iorganizationservice service, guid roleid)
{
// Add a security role
Addconnection (service, "teamroles_association", new entityreference () {logicalname = "role", id = roleid });
// Remove a security role
Removeconnection (service, "teamroles_association", new entityreference () {logicalname = "role", id = roleid });
}

/// <Summary>
/// Allocate a record to the team
/// </Summary>
/// <Param name = "service"> service </param>
/// <Param name = "target"> record object </param>
Public void assigntoteam (iorganizationservice service, entityreference target)
{
Assignrequest request = new assignrequest ();
Request. Target = target;
Request. assignee = new entityreference () {logicalname = entityname, id = teamid };
Service. Execute (request );
}

/// <Summary>
/// Delete the team
/// </Summary>
/// <Param name = "service"> service </param>
Public void Delete (iorganizationservice Service)
{
Service. Delete (entityname, teamid );
}

Public void addconnection (iorganizationservice service, string name, Params entityreference [] array)
{
Relationship ship = new relationship (name );
Associaterequest request = new associaterequest ();
Request. relationship = ship;
Request. Target = new entityreference () {logicalname = entityname, id = teamid };
Request. relatedentities = new entityreferencecollection ();
Request. relatedentities. addrange (array );
Service. Execute (request );
}

Public void removeconnection (iorganizationservice service, string name, Params entityreference [] array)
{
Relationship ship = new relationship (name );
Disassociaterequest request = new disassociaterequest ();
Request. relationship = ship;
Request. Target = new entityreference () {logicalname = entityname, id = teamid };
Request. relatedentities = new entityreferencecollection ();
Request. relatedentities. addrange (array );
Service. Execute (request );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.