Showing results for 
Search instead for 
Do you mean 

Button To Autogenerate An Opportunity

by ajappel on ‎11-01-2010 11:09 PM

Objective

Add two buttons onto the opportunity detail screen:

  • BtnRenew

o   Caption = “Renew”

  • BtnNoRenew

o   Caption = “Do Not Renew”

 

On Opportunity A, if I click the “Renew” button (BtnRenew) the following should happen:

  • Opportunity B should be created. 
  • Opportunity B should be assigned to the same Account as Opportunity A
  • Opportunity B’s description should = Opportunity A’s description + “ Renew” + [whatever else you need].
  • An Activity should be created on Opportunity B
  •  On Opportunity A, the custom Renew field (string) should be updated to have a “Yes” value.

 

On Opportunity A, if I click the “Don’t Renew” button (BtnNoRenew) the following should happen:

  • On Opportunity A, the custom Renew field (string) should be updated to have a “No” value.

Custom Fields (Required Step)

Three fields need to be added to the Opportunity table and will be added to the Opportunity Detail screen:

1)      Result (64 bit Text)

a.       Associate this with a picklist that contains values of ‘Yes’ and ‘No’

2)      ContractStart  (DateTime field)

3)      ContractEnd (DateTime field)

 

 

Approach 1 – Quick POC

We will add all of the code directly onto the “Renew” and “Don’t Renew” buttons’ On Click Action as a C# Snippet Action Item (Obsolete)

BtnRenew

Sage.Entity.Interfaces.IOpportunity CurOpp = this.BindingSource.Current as Sage.Entity.Interfaces.IOpportunity;

Sage.Entity.Interfaces.IOpportunity NewOpp = Sage.Platform.EntityFactory.Create<Sage.Entity.Interfaces.IOpportunity>();

Sage.Entity.Interfaces.IActivity newActivity = Sage.Platform.EntityFactory.Create<Sage.Entity.Interfaces.IActivity>();

 

CurOpp.Renew = "Yes";

//NewOpp.Account.ToString() = CurOpp.Account.ToString();

NewOpp.Description = CurOpp.Description + " Renewal 2010";                         

NewOpp.Type = "Renewal";

NewOpp.ContractStart = NewOpp.DateOpened;

NewOpp.ContractEnd = DateTime.Parse ("10/22/2011");

NewOpp.Notes = "Renewal from " + CurOpp.Description + ". Renewed on " + NewOpp.DateOpened;

NewOpp.Save();

String sId = NewOpp.Id.ToString();

newActivity.OpportunityId = sId;

newActivity.Category = "Renewal";

newActivity.Description = "Renewal";

newActivity.AccountName = NewOpp.Account.ToString();

newActivity.Save();    

Response.Redirect("Opportunity.aspx?entityId=" + sId);

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

BtnNoRenew

Sage.Entity.Interfaces.IOpportunity opp = this.BindingSource.Current as Sage.Entity.Interfaces.IOpportunity;

      opp.Renew = "No";

      opp.Save();

 

 

 

 

 

 

Approach 2 – Best Practice

We will add most of the Renewal code to a custom Opportunity Business Rule and then call the Business Rule during the “Renew” button’s On Click Action as a C# Snippet Action Item (Obsolete).  By adding the code to a business rule we will be able to call it from other places if needed.

 

Step 1 – Under Opportunity Add Custom Business Rule called “RenewRule”

Location: PrimaryStep

Name: RenewRule

Return: String



namespace Sage.BusinessRules.CodeSnippets

{

       public static partial class OpportunityBusinessRules

       {

              public static void RenewRuleStep(IOpportunity opportunity, out string result)

              {

 

                     //Run this if Renew button on Opportunity A is selected.

                     //Will create a new Opportunity B that includes some information from Opportunity A

                     //Will create an activity and add it to Opportunity B

 

                     Sage.Entity.Interfaces.IOpportunity NewOpp = Sage.Platform.EntityFactory.Create<Sage.Entity.Interfaces.IOpportunity>();

               Sage.Entity.Interfaces.IActivity newActivity = Sage.Platform.EntityFactory.Create<Sage.Entity.Interfaces.IActivity>();

 

                     opportunity.Renew = "Yes";

                     NewOpp.Description = opportunity.Description + " Renewal 2010";

                     NewOpp.Type = "Renewal";

                     NewOpp.ContractStart = NewOpp.DateOpened;

                     NewOpp.ContractEnd = DateTime.Parse("10/22/2011");

                     NewOpp.Notes = "Renewal from " + opportunity.Description + ". Renewed on " + NewOpp.DateOpened;

                     NewOpp.Save();

 

                     //Will save Opportunity B's id. 

                     //This will be to redirect the contect to Opportunity B when clicking the Renew button on Opportunity A

                     result = (NewOpp.Id.ToString());

 

                     //Creating an activity on Opportunity B.

                     newActivity.OpportunityId = result;

            newActivity.Category = "Renewal";

            newActivity.Description = "Renewal";

            newActivity.AccountName = NewOpp.Account.ToString();

            newActivity.Save();  

 

 

              }

       }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Step 2 – Call RenewRule from BtnRenew

Sage.Entity.Interfaces.IOpportunity opp = this.BindingSource.Current as Sage.Entity.Interfaces.IOpportunity;

String sId = opp.RenewRule();

Response.Redirect("Opportunity.aspx?entityId=" + sId);

 

We will call RenewRule directly from the “Renew” buttons’ On Click Action as a C# Snippet Action Item (Obsolete)

 

 

 

 

Step 3 –BtnNoRenew Code

Sage.Entity.Interfaces.IOpportunity opp = this.BindingSource.Current as Sage.Entity.Interfaces.IOpportunity;

      opp.Renew = "No";

      opp.Save();

 

 

Add code onto the BtnNoRenew’s On Click Action as a C# Snippet Action Item (Obsolete)

 

 

 

 

 

Comments
by Copper Elite Contributor
on ‎04-12-2011 08:55 PM

Nice writeup!  I wish I had found this about 2 hours ago!  I'll add tags Redirect

 

 

 

 

Register Read Guidelines Request Partner or Employee Access

What's New in 8.1

Labels