locked
MS CRM plugin problem RRS feed

  • Question

  • Dear All,

     

    I am using MS CRM 4.0.

    I need to make validation on some fields that can not be done in CRM out of box utility, for this reason I have created a new plugin to calculate and check if the new service request duration is available in the contract allotment remaining.

    This plugin must be triggered before saving the service request record.

    I have used plugin registration tool 2.2 to register it.

    I have registered this plugin for the Create, Update message but the plugin was not executed when create or update a service request record.

    I made some search and I found that we have to register the plugin step on the child pipeline instead of parent pipeline when we are handling a step for service request entity.

     

    And if we write code for a plug-in in that is used in a child pipeline, you must instantiate the CrmService manually using the following code.

     

    This code is taken from CRM SDK.

     

    [C#]

    /// <param name="context">The execution context that was passed to the plug-in's Execute method.</param>

    /// <param name="flag">Set to True to use impersonation.</param>

    /// <returns>A CrmServce instance.</returns>

    private CrmService CreateCrmService(IPluginExecutionContext context, Boolean flag)

    {

        CrmAuthenticationToken authToken = new CrmAuthenticationToken();

        authToken.AuthenticationType = 0;

        authToken.OrganizationName = context.OrganizationName;

     

        // Include support for impersonation.

        if (flag)

            authToken.CallerId = context.UserId;

        else

            authToken.CallerId = context.InitiatingUserId;

     

        CrmService service = new CrmService();

        service.CrmAuthenticationTokenValue = authToken;

        service.UseDefaultCredentials = true;

     

         // Include support for infinite loop detection.

        CorrelationToken corToken = new CorrelationToken();

        corToken.CorrelationId = context.CorrelationId;

        corToken.CorrelationUpdatedTime = context.CorrelationUpdatedTime;

        corToken.Depth = context.Depth;

     

        RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");

     

        service.Url = String.Concat(regkey.GetValue("ServerUrl").ToString(), "/2007/crmservice.asmx");

        service.CorrelationTokenValue = corToken;

        return service;

    }

     

     

    I have configured the crmService using the precedent procedure but when I triggered the plugin I have got an SQL Server Error.

     

    Error Details in the trace file:

     

    Error: Exception has been thrown by the target of an invocation.

     

    Error Number: 0x80044150

     

    Error Message: Generic SQL error.

     

    Do you have any solution for this case?

    Thanks for any insight you have.

     

    Best Regards

     

    Maroun Hbayter

    Monday, June 6, 2011 11:43 AM

Answers

  • So if it's not available how are you returning information to the user.  What you are trying to do might be better served by using jscript on the entity form event handlers in the UI designer.  You can then validate at the time when it is entered on the form using an onchange event or in the onsave.   You have full access to the CRM web service to look at other entities and perform operations in client side jscript just like you do in .NET on the server side using plugins.


    Jamie Miley
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Monday, June 6, 2011 1:26 PM
    Moderator