locked
Namespace 'XRM' could not be found RRS feed

  • Question

  • Hi All;

    Below is my code 

    in which i get a error that 'The  type or namespace name 'XrmServiceContext' could not be found ( are you missing a using directive or an assembly?)

    Any help much appreciated 

    Thanks

    // <copyright file="SumActivityPlugin.cs" company="Microsoft">
    // Copyright (c) 2014 All Rights Reserved
    // </copyright>
    // <author>Microsoft</author>
    // <date>1/15/2014 11:42:50 AM</date>
    // <summary>Implements the SumActivityPlugin Plugin.</summary>
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.1
    // </auto-generated>
    namespace TotalHoursSame.Plugins1
    {
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using Microsoft.Xrm.Sdk;
        using Microsoft.Crm.Sdk;
    
        using XRM;
        using System.ServiceModel;
    
        /// <summary>
        /// SumActivityPlugin Plugin.
        /// </summary>    
        public class SumActivityPlugin: Plugin
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="SumActivityPlugin"/> class.
            /// </summary>
            public void Execute(IServiceProvider serviceProvider)
            {
                IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                Entity entity;
                // Check if the input parameters property bag contains a target
                // of the create operation and that target is of type Entity.
                if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)
                {
                    // Obtain the target business entity from the input parameters.
                    entity = (Entity)context.InputParameters["Target"];
    
                    // Verify that the entity represents a contact.
                    if (entity.LogicalName != Incident.EntityLogicalName) { return; }
                }
                else
                {
                    return;
                }
    
    
    
                try
                {
                    IOrganizationServiceFactory serviceFactory =
                        (IOrganizationServiceFactory)serviceProvider.GetService(
                    typeof(IOrganizationServiceFactory));
                    IOrganizationService service =
                    serviceFactory.CreateOrganizationService(context.UserId);
          
                    XrmServiceContext xrm = new XrmServiceContext(service);
    
    
    
    
    
                    // Extract the tracing service.
                    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                    if (tracingService == null)
                    {
                        throw new InvalidPluginExecutionException("Failed to retrieve the tracing service.");
                    }
                    Entity postEntity = null;
                    Entity preEntity = null;
                    if (context.PostEntityImages.Contains("MyImage"))
                    {
                        postEntity = context.PostEntityImages["MyImage"];
                    }
                    if (context.PreEntityImages.Contains("MyImage"))
                    {
                        preEntity = context.PreEntityImages["MyImage"];
                    }
                    tracingService.Trace("MeesageName = " + context.MessageName);
                    if (context.MessageName.ToLower().Equals("delete"))
                    {
                        tracingService.Trace("Completed activity was delete recalc total duration for project");
                        CalcProjectActivities(xrm, tracingService, preEntity);
                    }
                    else
                    {
                        tracingService.Trace("calc project total duration");
                        //change state
                        CalcProjectActivities(xrm, tracingService, postEntity);
                    }
                }
                catch (FaultException ex)
                {
                    throw new InvalidPluginExecutionException(
                    "An error occurred in the plug-in.", ex);
                }
    
            }
    
            private void CalcProjectActivities(XrmServiceContext xrm, ITracingService tracingService, Entity reldEntity)
            {
                // tracingService.Trace("Get activity");
                // ActivityPointer activity = xrm.ActivityPointerSet.FirstOrDefault(ac => ac.ActivityId == new Guid(reldEntity["activityid"].ToString()));
                tracingService.Trace("Get all related activities");
                IQueryable activities = xrm.ActivityPointerSet.Where(ac => ac.RegardingObjectId != null && ac.RegardingObjectId.Id == ((EntityReference)reldEntity["regardingobjectid"]).Id && ac.ActualDurationMinutes != null && ac.StateCode.Value == ActivityPointerState.Completed);
                if (activities != null)// && activity != null)
                {
                    int totalSum = 0;
                    foreach (var a in activities)
                    {
                        totalSum += a.ActualDurationMinutes.Value;
                    }
                    ActivityPointer activity = activities.FirstOrDefault();
                    tracingService.Trace("total sum = " + totalSum);
                    if (activity != null && activity.RegardingObjectId.LogicalName == new_project.EntityLogicalName)
                    {
                        new_project relatedProject = xrm.new_projectSet.FirstOrDefault(proj => proj.new_projectId == activity.RegardingObjectId.Id);
                        if (relatedProject.new_totalhours == null && totalSum != 0)
                        {
                            relatedProject.new_totalhours = totalSum;
                            xrm.UpdateObject(relatedProject);
                            xrm.SaveChanges();
                        }
                        else if (relatedProject.new_totalhours != null && relatedProject.new_totalhours.Value != totalSum)
                        {
                            relatedProject.new_totalhours = totalSum;
                            xrm.UpdateObject(relatedProject);
                            xrm.SaveChanges();
                        }
                    }
                }
            }
        }
    }
    


    Pradnya07

    Wednesday, January 15, 2014 12:57 PM

All replies

  • Hi,

    Please re-check following link and try to generate Xrm.cs using the same way mentioned on the following post :

    http://dynamicslollipops.blogspot.ae/2011/07/mscrm-2011-early-binding-plugin.html


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    Wednesday, January 15, 2014 1:17 PM
  • Hi Vikram 

    Thanks for your reply 

    Can you please help me create xrm.cs file 

    The given web link is bit confusing 

    I am using CRM 2013 online


    Pradnya07


    • Edited by Simran08 Wednesday, January 15, 2014 2:13 PM online
    Wednesday, January 15, 2014 2:10 PM