email sending issue
-
16 April 2012 10:06
In my form i have view like my records ,submitted record
when i selected submitted records view from that i selected a record and send an a email from that record when the email is sent to user ,that record should be deactivated
guys if you have any solution so help me
ms crm
- Diedit oleh Dicaprio r 16 April 2012 10:53
Semua Balasan
-
16 April 2012 11:47
You can simply set up a workflow on the E-mail entity and set it to trigger when the status is change.
In the workflow, check if the status is Sent and deactivate the regarding record for the entity that you want when the condition meets.
Refer to the following screenshot for the configuration of the workflow.
-
16 April 2012 12:32
ya thanks for reply but my requirement is
i have an a entity let 'A' in that i have two views 'active record ' and 'submitted for review' record
suppose i send email from an 'active record' it should not deactivate
when a send record from 'submitted for review' view it should be deactivate
both have same field that the confusion occurs to do it
anyways i tried ur logic its work fine thanks
ms crm
-
16 April 2012 13:41
thanks linn i did it do you business logic for the same workflow
because i want to make it through plug-in
ms crm
-
16 April 2012 14:16Glad to know that my answer help you somehow even though it's not exactly as you want.
-
27 April 2012 5:26
hiii linn can do the same process through the plug-in to change the status of the record if its possible can you explain me ?
if you have code regarding this issue please send it to me?
ms crm
-
27 April 2012 6:12
hello Linn,
your answer worked very well for me.
Thank you
-
27 April 2012 7:39
Hi,
Reference the following code and modify accordingly (e.g. new_test to your desired entity name and add some logic).
I believe it will trigger for SetStateDynamicEntity message but in case if it's not triggering, try SetState and Send message.
You'll also need to register PostImage with RegardingObjectId, StateCode and StatusCode.
public void Execute(IServiceProvider serviceProvider) { try { IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); if (context.PrimaryEntityName == "email" && (context.MessageName == "SetState" || context.MessageName == "SetStateDynamicEntity" || context.MessageName == "Send")) { IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); if (context.PostEntityImages["PostImage"].Attributes.Contains("regardingobjectid") && context.PostEntityImages["PostImage"].Attributes.Contains("statecode") && context.PostEntityImages["PostImage"].Attributes.Contains("statuscode") && ((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).LogicalName == "new_test" // Update the entity type you want to take effect or remove this line if you want to trigger for all types && ((OptionSetValue)(context.PostEntityImages["PostImage"]["statecode"])).Value == 1 // Completed && ((OptionSetValue)(context.PostEntityImages["PostImage"]["statuscode"])).Value == 3 // Sent ) { SetStateRequest setStateReq = new SetStateRequest(); setStateReq.EntityMoniker = new EntityReference(((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).LogicalName, ((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).Id); setStateReq.State = new OptionSetValue(1); // Inactive setStateReq.Status = new OptionSetValue(2); // Inactive SetStateResponse response = (SetStateResponse)service.Execute(setStateReq); } } } catch (System.Web.Services.Protocols.SoapException ex) { throw new InvalidPluginExecutionException(ex.InnerException.Message, ex.InnerException); } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message, ex); } }
-
02 Mei 2012 5:21hi linn there is an error in setstaterequest whether i need to add any references to it in 2011
ms crm
-
02 Mei 2012 6:46You'll need to reference "..\CRMWeb\bin\Microsoft.Crm.Sdk.Proxy.dll" in your project and reference Microsoft.Crm.Sdk.Messages in your code.
-
05 Mei 2012 10:33hi dude i had an a requirement that when an email is sent i want to update some field in the record how does it possible through plug-in if you have any for please send it to me
ms crm
-
07 Mei 2012 2:31
You want to update the regarding object record of the email?
If so, you can replace the "SetStateRequest" code block from the above code with update code by referencing the following code snippet.
Entity regardingRecord = new Entity(new EntityReference(((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).LogicalName); regardingRecord.Id = ((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).Id; regardingRecord["new_testattribute"] = "New Value"; service.Update(regardingRecord);
Please "Mark As Answer" for the posts that helped you solving the problem. This will help others with similar problem identify the answer and also close this thread as resolved. -
07 Mei 2012 14:24
hello linn thanks for the reply dude can help me how to get business logic for the plug-in
am facing some difficulties to create an a plug-in can you give me some tips to create a plug-in as easy as
once again thanks for the reply
ms crm
-
07 Mei 2012 14:26
dude i facing some runtime error in creating this plug-in this is not debugging it all can find what mistake in that
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;
using System.Runtime.Serialization;
using Microsoft.Crm.Sdk.Messages;
namespace setupdate
{
public class Update : IPlugin
{
public void Execute(IServiceProvider serviceprovider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceprovider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId);
// if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
// {
// Entity entity = (Entity)context.InputParameters["Target"];
if (context.PrimaryEntityName == "email" && context.MessageName == "SetStateDynamicEntity" || context.MessageName == "SetState" || context.MessageName == "send")
{
if (context.PostEntityImages["PostImage"].Attributes.Contains("regardingobjectid")
// && context.PostEntityImages["PostImage"].Attributes.Contains("statecode")
&& context.PostEntityImages["PostImage"].Attributes.Contains("statuscode")
&& ((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).LogicalName == "lead" // Update the entity type you want to take effect or remove this line if you want to trigger for all types
// && ((OptionSetValue)(context.PostEntityImages["PostImage"]["statecode"])).Value == 1 // Completed
&& ((OptionSetValue)(context.PostEntityImages["PostImage"]["statuscode"])).Value == 6 // Sent
)
{
Entity regardingRecord = new Entity((((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).LogicalName));
regardingRecord.Id = ((EntityReference)context.PostEntityImages["PostImage"]["regardingobjectid"]).Id;
regardingRecord["new_assignedto"] = 0;
regardingRecord["description"] = "test job docket";
regardingRecord["new_jobstatus"] = 1;
service.Update(regardingRecord);dude if you find some solution please help me
ms crm
-
07 Mei 2012 17:01
What are the data types of new_assignedto and new_jobstatus custom attributes?
If those are OptionSet, you have to set the value as the following.
regardingRecord["new_assignedto"] = new OptionSetValue(0); regardingRecord["new_jobstatus"] = new OptionSetValue(1);
If those are two option (bit) attributes, set boolean (true/false) values.
If both of those are integer values, I can't think of any error by looking at your code.
Anyway, you can debug your plugin by attaching to the worker process or using CRM 2011 Plugin Testing Tools
By the way, it's not concerning with your run time error but there's something not right with the following line in your code.
if (context.PrimaryEntityName == "email" && context.MessageName == "SetStateDynamicEntity" || context.MessageName == "SetState" || context.MessageName == "send")
Modify that line a bit as follows.
if (context.PrimaryEntityName == "email" && (context.MessageName == "SetStateDynamicEntity" || context.MessageName == "SetState" || context.MessageName == "Send"))
Please "Mark As Answer" for the posts that helped you solving the problem. This will help others with similar problem identify the answer and also close this thread as resolved.
-
08 Mei 2012 13:35ya linn it was showing business process error in the code do you have any idea with that
ms crm
-
08 Mei 2012 17:27
"Business Process Error" is the generic error title of a plugin.
Unless I don't know the error details, there's no way I can' guess the root cause of the problem.
You've got to debug your plug as I mentioned in the previous post or you need to trace in your code to know at which step your plugin was throwing an error.