Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Retrieve message name plugin: Access is denied Error

$
0
0

The plugin seams to be triggered but I get this error <Message>Access is denied. I thought that retrieving info about a record using a plugin I wont get this type of errors. The full error message is:

Microsoft Dynamics CRM Error Report Contents

<CrmScriptErrorReport>
  <ReportVersion>1.0</ReportVersion>
  <ScriptErrorDetails>
   <Message>Access is denied.  ????????????????????
</Message>
   <Line>316</Line>
   <URL>/main.aspx?etc=2&extraqs=%3f_gridType%3d2%26etc%3d2%26id%3d%257bA8B33925-2061-E111-83BA-005056B1002A%257d%26pagemode%3diframe%26preloadcache%3d1366281487235%26rskey%3d379065732&pagetype=entityrecord</URL>
   <PageURL>/main.aspx?etc=2&extraqs=%3f_gridType%3d2%26etc%3d2%26id%3d%257bA8B33925-2061-E111-83BA-005056B1002A%257d%26pagemode%3diframe%26preloadcache%3d1366281487235%26rskey%3d379065732&pagetype=entityrecord</PageURL>
   <Function></Function>
   <CallStack>
   </CallStack>
  </ScriptErrorDetails>
  <ClientInformation>
   <BrowserUserAgent>Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)</BrowserUserAgent>
   <BrowserLanguage>en-us</BrowserLanguage>
   <SystemLanguage>en-us</SystemLanguage>
   <UserLanguage>en-gb</UserLanguage>
   <ScreenResolution>1920x1080</ScreenResolution>
   <ClientName>Web</ClientName>
   <ClientTime>2013-04-18T11:38:45</ClientTime>
  </ClientInformation>
  <ServerInformation>
    <OrgLanguage>1033</OrgLanguage>
    <OrgCulture>2057</OrgCulture>
    <UserLanguage>1033</UserLanguage>
    <UserCulture>2057</UserCulture>
    <OrgID>{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}</OrgID>
    <UserID>{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}</UserID>
    <CRMVersion>5.0.9690.2165</CRMVersion>
  </ServerInformation>
</CrmScriptErrorReport>

The general configuration of the plugin is:

Message: Retrieve

Primary entity: contact

Stage: pre-operation

Mode : synchronous

And the code is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;


namespace TestLibrary1
{
    public class Class1 :IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
                serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            // Obtain the target entity from the input parmameters.
            EntityReference entity = (EntityReference)context.InputParameters["Target"];

            ColumnSet cols = new ColumnSet(new String[] { "lastname", "firstname", "address1_name" });

            var contact = service.Retrieve("contact", entity.Id, cols);

            if (contact != null)
            {
                contact["lastname"] = "plugin: I have been triggered";
                contact["firstname"] = "plugin: I have been triggered";
                service.Update(contact);
            }

        }
    }
}

Thank you


Viewing all articles
Browse latest Browse all 8223

Trending Articles