web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

crm simple plugin development

(0) ShareShare
ReportReport
Posted on by

I need to develop a plugin in c# when the zipcode is 12345 the freight amount in quote is set to $100.

I have the following logic..but it doesn't work:

case "Create":
if (pluginExecutionContext.InputParameters.Contains("Target") &&
pluginExecutionContext.InputParameters["Target"] is Entity &&
pluginExecutionContext.OutputParameters.Contains("id"))
{
Entity entity = (Entity)pluginExecutionContext.InputParameters["Target"];
tracingService.Trace("Create [" + entity.LogicalName + "], id [" + entity.Id + "]");

if (entity.LogicalName == "quote")
{
quoteId = entity.Id;
OrganizationServiceContext orgContext = new OrganizationServiceContext(orgService);
Entity quote = orgService.Retrieve("quote", quoteId, new ColumnSet("freightamount", "shipto_postalcode"));

if (!quote.Attributes.Contains("shipto_postalcode"))
{

return;

}

string zipCode = quote.Attributes["shipto_postalcode"].ToString();

if (zipCode.Equals("12345"))

{

quote.Attributes["freightamount"] = 100;

orgService.Update(quote);

}


}
}
break;

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Swetha Poojary Salaskar Profile Picture
    326 on at
    RE: crm simple plugin development

    Where do you get case value as Create?

    Rest of the plugin code looks good.

    instead of case you can write below if condition and rest of the code within it

    if (context.MessageName.ToUpper() == “CREATE”){

    }

    Cheers,

    Swetha

    PS: please mark as verified if it helped you resolve your problem :)

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: crm simple plugin development

    Hello ,

    Try with this - 

        public class PostQuoteCreate : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService orgService = serviceFactory.CreateOrganizationService(context.UserId);
                if (context.InputParameters.Contains("Target") &&
              context.InputParameters["Target"] is Entity)
                {
                    Entity entity = (Entity)context.InputParameters["Target"];
                    tracingService.Trace("Create [" + entity.LogicalName + "], id [" + entity.Id + "]");
    
                    if (entity.LogicalName == "quote")
                    {
                        Guid quoteId = entity.Id;
                        Entity quote = orgService.Retrieve("quote", quoteId, new ColumnSet("freightamount", "shipto_postalcode"));
                        if (!quote.Attributes.Contains("shipto_postalcode"))
                        {
                            return;
                        }
    
                        string zipCode = quote.Attributes["shipto_postalcode"].ToString();
    
                        if (zipCode.Equals("12345"))
                        {
    
                            quote.Attributes["freightamount"] = 100;
                            orgService.Update(quote);
    
                        }
    
    
                    }
                }
            }


  • Shidin Haridas Profile Picture
    3,497 on at
    RE: crm simple plugin development

    Hey Sidsubedi ,

    You have already another forum question along the same lines. Please close that question first, so that it helps others.

  • Community Member Profile Picture
    on at
    RE: crm simple plugin development

    Hi  Goutam,

    First of all thanks for your help but i executed your code but it didn't work... what may be going wrong in this?

  • gdas Profile Picture
    50,091 Moderator on at
    RE: crm simple plugin development

    Hi,

    Can you please implement trace log and try to debug your code and let me know which line you are getting error.

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: crm simple plugin development

    Hi there,

    I think it may be because of type casting.

    Can you please try with convert your value into money as shown below:

    if (zipCode.Equals("12345"))

    {

    quote.Attributes["freightamount"] = new Money(100);

    orgService.Update(quote);

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans