locked
Map fields from activity to opportunity RRS feed

  • Question

  • Hi, Have modified the 'Letter' activity to my own activity. Need to map some custom attributes from the newly created activity to the opportunity when the 'Convert To Opportunity' is clicked. Is there a way to do  this? Thanks

    Tuesday, May 26, 2009 5:08 PM

Answers

  • An alternatie approach would be to create a manual workflow which creates the opportunity for you from the activity. This would allow you to map whatever fields you like via the workflow itself. The only thing you'd need to do then would be to hide the original conversion utility. Others may know how to approach this problem but, if it is possible, it should be a lot simpler to code.

    Leon Tribe
    Want to hear me talk about all things CRM? Check out my blog
    • Proposed as answer by Leon TribeMVP Wednesday, May 27, 2009 9:29 PM
    • Marked as answer by IamaNovice Thursday, May 28, 2009 4:55 PM
    Wednesday, May 27, 2009 9:29 PM
  • Once you convert the activity its regarding lookup field is set with the opportunity value. In order for the activity to do that the opportunity needs to exist. At the point of opportunity creation the activity is not yet part of its history. This is why the opportunity create event is not suited for this type of mapping.

     

    Leon suggestion is an option you should consider only if you’re not interested in further UI interaction like returning friendly error messages to the user or opening the opportunity once it’s created.

     

    One more thing worth mentioning - the user won’t be able to see the opportunity in the activity regarding field until he reopens the activity if the user was to change the regarding field after the workflow is ran you either won’t see the activity inside the opportunity history or the user regarding field will be overridden by the opportunity – whichever comes first.

     

     


    Blog: http://mscrm4ever.blogspot.com/ * Website: http://gicrm.upsite.co.il/
    • Marked as answer by IamaNovice Thursday, May 28, 2009 4:55 PM
    Thursday, May 28, 2009 1:25 AM

All replies

  • Ultimately, the problem you have is the opportunity is associated to the campaign while the activity is attached to a campaign response. Relationship mapping is no good for you because you can't map from activities. Workflow won't work because there is no path back to the activity to work out what fields to bring across. I'm thinking the only way to achieve this would be through code.

    Leon Tribe
    Want to hear me talk about all things CRM? Check out my blog
    Wednesday, May 27, 2009 3:53 AM
  • Hi Leon, You're right. That's what I am finally resorting to. Since it is just a week that I am int CRM, I face some challenge there too.

    I have modified the 'Letter' activity to a 'Presentation' activity.
    My approach: Write a plug in that will execute when the opportunity is created. The plug in will access the activity in the just-created opportunity and populate the required attributes. I am stuck in this stage: how do I find the activity which exists in the opportunity's history using the plug in. Following is all I have written in the plug-in. Any ideas, how to proceed, thanks

    public

     

    void Execute(IPluginExecutionContext context)

    {

     

    DynamicEntity entity = null;

    #region

     

    Verify execution context

     

    if (context.InputParameters.Contains("Target") &&

    context.InputParameters.Properties[

    "Target"] is DynamicEntity)

    {

    entity = (

    DynamicEntity)context.InputParameters.Properties["Target"];

     

    if (entity.Name != EntityName.opportunity.ToString())

     

    return;

    }

     

    else

    {

     

    return;

    }

    #endregion

     

    Verify execution context

     

     

    }

    Wednesday, May 27, 2009 4:48 PM
  • The opportunity does not contain the a reference to activity from which it was originated. This is also true for the convert activity button that come out of box.

     

    You started off in the right direction by adding a new toolbar button that triggers the process. What you should do is write a plug-in on the letter activity update message.

     

    You can identify the process by adding a new bit field to the letter entity. When the user clicks on the custom convert to opportunity button you set the bit field to true and do a crmForm.Save() which triggers the update plug-in. E.g.

     

    function CustomConvert()
    {
         crmForm.new_conversionproc.DataValue = true;

         crmForm.new_conversionproc.ForceSubmit = true; // field is disabled by default.

         crmForm.Save();
    }

     

     

    Your plug-in then identifies that this is a convert operation by checking that the bit field is true e.g.

     

    If (context.InputParameters.Contains(ParameterName.Target)
    {
         DynanicEntity Target = context.InputParameters[ParameterName.Target] as DynamicEntity;

         If (Target.Properties.Contains(“new_conversionproc”) )

         {

                   Boolean conversionProc = (Boolean)Target.Properties[“new_conversionproc”];

                   If (conversionProc == true)

    {
         //conversion here…
    }

         }
    }

     

    Now create a new opportunity with the fields you want to map from the current activity (Target), optionally set the activity regarding object id to the newly created opportunity.

     


    Blog: http://mscrm4ever.blogspot.com/ * Website: http://gicrm.upsite.co.il/
    Wednesday, May 27, 2009 7:33 PM
  • When I click on 'Convert Activity to Opportunity' and open the Opportunity screen (after clicking on ok from the dialog), I see the activity in the Opportunity History. That's why I thought we can write a plug in to be executed in 'Create' of the opportunity and access teh activity. Let me know if my understanding is worng. Thanks a lot for your help.

    Wednesday, May 27, 2009 9:01 PM
  • An alternatie approach would be to create a manual workflow which creates the opportunity for you from the activity. This would allow you to map whatever fields you like via the workflow itself. The only thing you'd need to do then would be to hide the original conversion utility. Others may know how to approach this problem but, if it is possible, it should be a lot simpler to code.

    Leon Tribe
    Want to hear me talk about all things CRM? Check out my blog
    • Proposed as answer by Leon TribeMVP Wednesday, May 27, 2009 9:29 PM
    • Marked as answer by IamaNovice Thursday, May 28, 2009 4:55 PM
    Wednesday, May 27, 2009 9:29 PM
  • Once you convert the activity its regarding lookup field is set with the opportunity value. In order for the activity to do that the opportunity needs to exist. At the point of opportunity creation the activity is not yet part of its history. This is why the opportunity create event is not suited for this type of mapping.

     

    Leon suggestion is an option you should consider only if you’re not interested in further UI interaction like returning friendly error messages to the user or opening the opportunity once it’s created.

     

    One more thing worth mentioning - the user won’t be able to see the opportunity in the activity regarding field until he reopens the activity if the user was to change the regarding field after the workflow is ran you either won’t see the activity inside the opportunity history or the user regarding field will be overridden by the opportunity – whichever comes first.

     

     


    Blog: http://mscrm4ever.blogspot.com/ * Website: http://gicrm.upsite.co.il/
    • Marked as answer by IamaNovice Thursday, May 28, 2009 4:55 PM
    Thursday, May 28, 2009 1:25 AM
  • Adi/Leon, Thanks a lot for all your help. Finally reached a solution retaining the out-of-the boc functionality but with no custom button, no workflows etc.,

    I modified the Letter activity to my custom activity. Added all custom attributes and removed those that I did not need. When the 'Convert To Opportunity' is clicked, after the opportunity is created and before the opportunity form is opened, the newly created opportunityId is updated in the regarding field of the activity. So, I created a callout for PostUpdate of letter, where with the help of the pre and postentityimage of regardingobjectid, I populated all the required fields from activity to opportunity. This way, the out of the box functionality of the activity, conversion option and the opportunity is all retained. Hope this helps someone. Thanks again.
    Friday, June 5, 2009 5:36 PM