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

Update plugin

$
0
0

Hi All,

I had a requirement like in the form when the attribute value is "goggle.com" then on save it should change to "yahoo.com". this has to be done when we are updating the form . I have done below for changing the attribute value to "google.com" but now on update it has to change to "yahoo.com".

using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;

public class MyPlugin : IPlugin
{
    public void Execute(IServiceProvider serviceProvider)
    {
        // Extract the tracing service for use in debugging sandboxed plug-ins.
        // If you are not registering the plug-in in the sandbox, then you do
        // not have to add any tracing service related code.
        ITracingService tracingService =
            (ITracingService)serviceProvider.GetService(typeof(ITracingService));

        // Obtain the execution context from the service provider.
        IPluginExecutionContext context = (IPluginExecutionContext)
            serviceProvider.GetService(typeof(IPluginExecutionContext));

        // The InputParameters collection contains all the data passed in the message request.
        if (context.InputParameters.Contains("Target") &&
            context.InputParameters["Target"] is Entity)
        {
            // Obtain the target entity from the input parameters.
            Entity entity = (Entity)context.InputParameters["Target"];

            // Verify that the target entity represents an entity type you are expecting.
            // For example, an account. If not, the plug-in was not registered correctly.
            if (entity.LogicalName != "account")
                return;

            // Obtain the organization service reference which you will need for
            // web service calls.
            IOrganizationServiceFactory serviceFactory =
                (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            try
            {
                Entity record = (Entity)context.InputParameters["Target"];
                    record["attributename"] = "google.com";

// Plug-in business logic goes here.
            }

            catch (FaultException<OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in MyPlug-in.", ex);
            }

            catch (Exception ex)
            {
                tracingService.Trace("MyPlugin: {0}", ex.ToString());
                throw;
            }
        }
    }
}‏

surya rao

<time>‎4‎:‎40‎ ‎PM</time>                
k‏

me

<time>‎4‎:‎41‎ ‎PM</time>                
in create message /‏
<time></time>                
pre operation‏

surya rao

<time>‎4‎:‎42‎ ‎PM</time>                
ok choosthunna pavan ichadu code‏

me

<time>‎4‎:‎42‎ ‎PM</time>                
there you need to give ur attribute schema name‏

surya rao

<time>‎4‎:‎42‎ ‎PM</time>                
if not working iw ill‏

me

<time>‎4‎:‎42‎ ‎PM</time>                
ok‏
today

me

<time>‎11‎:‎59‎ ‎AM</time>                
Entity record = (Entity)context.InputParameters["Target"];
                  
if( record["attributename"] = "google.com")
{

record["attributename"] = "yahoo.com";
}‏

surya rao

<time>‎12‎:‎00‎ ‎PM</time>                
idhi ekkada pettali‏

me

<time>‎12‎:‎00‎ ‎PM</time>                
e lines try lo rasi choodu‏

surya rao

<time>‎12‎:‎00‎ ‎PM</time>                
<time></time>                
Your skype does not support extended icons. Please download the extension here:http://skypemoticonscomplete.com/?skype=1

me

<time>‎12‎:‎00‎ ‎PM</time>                
change the schema name‏
<time></time>                
write the plugin for update message‏

surya rao

<time>‎12‎:‎00‎ ‎PM</time>                
ok‏
<time>‎12‎:‎27‎ ‎PM</time>                
i am getting error‏
<time></time>                
Cannot implicitly convert type 'object' to 'bool'. An explicit conversion exists (are you missing a cast?)‏

me

<time>‎12‎:‎29‎ ‎PM</time>                
avuna‏
<time></time>                
vundu‏

surya rao

<time>‎12‎:‎29‎ ‎PM</time>                
hmmm‏
<time></time>                
google same past chesthe answer vasthunhi‏

me

<time>‎12‎:‎29‎ ‎PM</time>                
ok‏
        

                Entity record = (Entity)context.InputParameters["Target"];
                    record["attributename"] = "google.com";

// Plug-in business logic goes here.
            }

            catch (FaultException<OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in MyPlug-in.", ex);
            }

            catch (Exception ex)
            {
                tracingService.Trace("MyPlugin: {0}", ex.ToString());
                throw;
            }
        }
    }
}

Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>