we can check using below condition as shown in below figure.
Dynamics 365 , Microsoft Dynamics CRM, CRM 2016,Dynamics 365,Plugins,javascript,Plugin,C#.net ,Dynamics Customer Engagement MS CRM 2011,MS CRM 2013, Work FLows, Real Time worklfows, Customer worklfows,Dynamics365,MB 901 certification,
Dynamics 365
Showing posts with label CRM. Show all posts
Showing posts with label CRM. Show all posts
Thursday, July 23, 2020
Dynamics 365 - condition to check owner is team or user while send email
In dynamics 365 while sending emails on assigning Case or any other entity record Required to send an email to user. here We may assign case to team initially and then to user manually . CRM may not send email to team . It can send email to user., so in work flow we need to check for the whether owner is team or user .
Monday, November 4, 2013
Close quote Plugin code in c#.net
Close quote Plugin code in c#.net
Below code to achieve logic
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm.Sdk.Messages;
namespace CloseQuote
{
public class PluginCloseQuote:IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
try
{
// Plugin to close the quote
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.Depth<2)
{
Entity entity = context.InputParameters["Target"] as Entity;
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(new Guid?(context.UserId));
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains("PostImage")) ? context.PostEntityImages["PostImage"] : null;
if (postImageEntity.GetAttributeValue<bool>("pmax_isclosequote"))
{
if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
{
//method to Activate quote
SetEntityStatus(service, entity.Id, "quote");
}
//method to close quote
CloseQuoteRequest req = new CloseQuoteRequest();
Entity quoteClose = new Entity("quoteclose");
quoteClose.Attributes.Add("quoteid", new EntityReference("quote", entity.Id));
quoteClose.Attributes.Add("subject", "Customer was mean so we just closed it.");
req.QuoteClose = quoteClose;
req.RequestName = "CloseQuote";
OptionSetValue o = new OptionSetValue();
o.Value = 5;
req.Status = o;
CloseQuoteResponse resp = (CloseQuoteResponse)service.Execute(req);
}
else if (postImageEntity.GetAttributeValue<bool>("pmax_isactivatequote"))
{
if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
{
//method to Activate quote
SetEntityStatus(service, entity.Id, "quote");
}
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(
"An error occurred in the CloseQuote.PluginCloseQuote Plug-in" + ex.Message, ex);
}
}
//activate the quote
private void SetEntityStatus(IOrganizationService service, Guid recordGUID, string entityName)
{
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = recordGUID;
setState.EntityMoniker.Name = entityName;
setState.EntityMoniker.LogicalName = entityName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 1;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 3;
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
}
private void SetEntityStatusActive(IOrganizationService service, Guid recordGUID, string entityName)
{
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = recordGUID;
setState.EntityMoniker.Name = entityName;
setState.EntityMoniker.LogicalName = entityName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 3;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 5;
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
}
private SetStateRequest inactiveSuspect(Entity entSuspect)
{
//to set prospect record inactive
//WinOpportunityRequest
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = entSuspect.Id;
setState.EntityMoniker.Name = "quote";
setState.EntityMoniker.LogicalName = entSuspect.LogicalName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 0;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 1;
return setState;
//
}
}
}
Below code to achieve logic
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm.Sdk.Messages;
namespace CloseQuote
{
public class PluginCloseQuote:IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
try
{
// Plugin to close the quote
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.Depth<2)
{
Entity entity = context.InputParameters["Target"] as Entity;
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(new Guid?(context.UserId));
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains("PostImage")) ? context.PostEntityImages["PostImage"] : null;
if (postImageEntity.GetAttributeValue<bool>("pmax_isclosequote"))
{
if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
{
//method to Activate quote
SetEntityStatus(service, entity.Id, "quote");
}
//method to close quote
CloseQuoteRequest req = new CloseQuoteRequest();
Entity quoteClose = new Entity("quoteclose");
quoteClose.Attributes.Add("quoteid", new EntityReference("quote", entity.Id));
quoteClose.Attributes.Add("subject", "Customer was mean so we just closed it.");
req.QuoteClose = quoteClose;
req.RequestName = "CloseQuote";
OptionSetValue o = new OptionSetValue();
o.Value = 5;
req.Status = o;
CloseQuoteResponse resp = (CloseQuoteResponse)service.Execute(req);
}
else if (postImageEntity.GetAttributeValue<bool>("pmax_isactivatequote"))
{
if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
{
//method to Activate quote
SetEntityStatus(service, entity.Id, "quote");
}
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(
"An error occurred in the CloseQuote.PluginCloseQuote Plug-in" + ex.Message, ex);
}
}
//activate the quote
private void SetEntityStatus(IOrganizationService service, Guid recordGUID, string entityName)
{
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = recordGUID;
setState.EntityMoniker.Name = entityName;
setState.EntityMoniker.LogicalName = entityName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 1;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 3;
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
}
private void SetEntityStatusActive(IOrganizationService service, Guid recordGUID, string entityName)
{
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = recordGUID;
setState.EntityMoniker.Name = entityName;
setState.EntityMoniker.LogicalName = entityName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 3;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 5;
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
}
private SetStateRequest inactiveSuspect(Entity entSuspect)
{
//to set prospect record inactive
//WinOpportunityRequest
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = entSuspect.Id;
setState.EntityMoniker.Name = "quote";
setState.EntityMoniker.LogicalName = entSuspect.LogicalName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 0;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 1;
return setState;
//
}
}
}
Subscribe to:
Posts (Atom)