Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Others
cms.evaluation
cms.general
comm.businessdesk
comm.campaigns_csf
comm.catalog
comm.datawarehousing
comm.deploy.
comm.general
comm.sdk
comm.solutionsites
comm.userprofilemgt
commerce.analysis
crm
crm.deployment
crm.developer
hiserver.general
mobility.miserver
sharep.portal.config
sharep.portal.dev
sharep.portal.docmgmt.
sharep.portal.installation
sharep.portal.sdk
sharep.portal.search
sharep.team.caml
sharep.teamservices
sharep.windowsservices
sharep.winservices.dev
sharepoint.portalserver
siteserv.knowledgemgr
siteserver.analysis
siteserver.commerce
siteserver.css
siteserver.general
siteserver.publishing
siteserver.sdk
siteserver.search
site-server.site-mgmt
site-server.webpost
  
 
date: Mon, 15 Sep 2008 11:43:32 +0200,    group: microsoft.public.crm.developer        back       


sharing serviceappointments?   
Hey All!

Is it possible to share serviceappointments?

I didn't found any menuitem in the serviceappointment forms, but the sdk 
discribles you can do it by code (ModifyShare, GrantAccess).
Well done, I've written a plugin to do that and it works without any 
exceptions (there are also no exceptions in crm traces or sql profiler).

!!! But I've got no results !!!

Our setup looks like this:
- User "Administrator" (all rights)
- User "dv10" -> Security Role "Service" (Organisation wide read on all 
entities)
-Team "Service" -> Member "dv10"
- Plugin "ShareService" (Update, Create on serviceappointments, run as 
CallingUser)

Workflow:
- "Administrator" is creating (and saveing) a new serviceappoinment.
- "ShareService" is modifing rights.
- "dv10" is opening the same serviceappoinment.

Target:
- The created/ edited Serviceappointment should be shared with read- and 
write rights.

Here is the Plugin snippit:

public void Execute(IPluginExecutionContext context)
      {
         #region Prolog

         // Create the CrmService instance using the provided context 
method.
         using (ICrmService service = 
(ICrmService)context.CreateCrmService(true))
         {
                ....
         #endregion Prolog

         #region SetShares

            ModifyShareByServiceTeam(service, postImageEntity, entityGuid, 
context.PrimaryEntityName, "Service Systemuser");

            //GrantAccessToEntity(service, postImageEntity, entityGuid, 
context.PrimaryEntityName, "Service Systemuser");
         #endregion SetShares
         }
      }

private void ModifyShareByServiceTeam(ICrmService service, DynamicEntity 
postImageEntity, string entityGuid, string primaryEntityName, string 
teamName)
      {
         StringBuilder sb = new StringBuilder();
         sb.Append("<fetch mapping='logical'>");
         sb.Append("<entity name='team'>");
         sb.Append("<attribute name='teamid'/>");
         sb.Append("<attribute name='name'/>");

         sb.Append("<filter type='and'>");
         sb.Append("<condition attribute='name' operator='eq' value='" + 
teamName + "'/>");
         sb.Append("</filter>");

         sb.Append("</entity>");
         sb.Append("</fetch>");

         BusinessEntityCollection bec = 
service.RetrieveMultiple(GetByFetch(service, sb.ToString()));
         Guid teamId = Guid.Empty;

         if (bec.BusinessEntities.Count == 0)
            return;

         bool result = false;
         for (int i = 0; i < bec.BusinessEntities.Count; i++)
         {
            teamId = ((team)bec.BusinessEntities[i]).teamid.Value;
            result = this.ModifyShare(service, teamId.ToString(), 
entityGuid, primaryEntityName, (int)eRights.Write);

            if (!result)
               throw new InvalidPluginExecutionException("ModifyShare 
failed!");
         }
      }


public bool ModifyShare(ICrmService service, string TeamGuid, string 
EntityGuid, string EntityName, int Rights)
      {
         // Create the Security Principal Object
         SecurityPrincipal principal = new SecurityPrincipal();
         principal.Type = SecurityPrincipalType.Team;

         // PrincipalId is the Guid of the user/team whose access is being 
modified
         principal.PrincipalId = new Guid(TeamGuid);

         // Create the PrincipalAccess
         PrincipalAccess principalAccess = new PrincipalAccess();

         // Set the PrincipalAccess Object's Properties
         principalAccess.Principal = principal;

         // gives the principal access to read
         switch (Rights)
         {
            case 0: principalAccess.AccessMask = 0;
               break;
            case 1: principalAccess.AccessMask = AccessRights.ReadAccess;
               break;
            case 2: principalAccess.AccessMask = AccessRights.ReadAccess | 
AccessRights.WriteAccess;
               break;
         }

         // Create the Target Object for the Request
         //TargetOwnedDynamic target = new TargetOwnedDynamic();
         TargetOwnedServiceAppointment target = new 
TargetOwnedServiceAppointment();

         // EntityId is the Guid of the entity whose access is being 
modified
         // target.EntityName = EntityName;
         target.EntityId = new Guid(EntityGuid);

         // Create the Request Object
         ModifyAccessRequest modify = new ModifyAccessRequest();

         // Set the Request Object's Properties
         modify.PrincipalAccess = principalAccess;
         modify.Target = target;

         // Execute the Request
         try
         {
            // ModifyAccessResponse modified = (ModifyAccessResponse)
            service.Execute(modify);
         }
         catch (System.Web.Services.Protocols.SoapException ex)
         {
            Logger.WriteError(VER + "An error occurred in the plug-in.\r\n" 
+ ex.Message + "." + ex.Detail.InnerText);

            return false;
         }
         return true;
      }

I hope you can help!

best regards,

Michael
date: Mon, 15 Sep 2008 11:43:32 +0200   author:   Michael Fritsch

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us