Cloning an Opportunity using the ASP COM API

Less than one minute read time.

I have written earlier about cloning or copying existing records. Please see the article Using the COM API to Clone a Record.

This article provides a worked example on how you can use that article to add a button to the opportunity summary screen that will copy an existing opportunity record and start a new workflow.

To do this we need to create a New Button group linked to the opportunitysummary system action.

Administration -> Advanced Customization -> Button Groups

The button needs to call an ASP page. I have called mine cloneoppo.asp.

The code will need to copy the record, save it and then redirect the page to the list of opportunities to show the new opportunity has been created.

The ASP file was saved as cloneoppo.asp uder the CustomPages folder e.g.

C:\Program Files\Sage\CRM\[installname]\WWWRoot\CustomPages\cloneoppo.asp


");
//copy the data from the first record to the second
e = new Enumerator(FirstRecord);
while (e.item())
{
  NewRecord(e.item()) = FirstRecord(e.item())
  e.moveNext();
}
 
//set the fields and properties unique to the new record
NewRecord.oppo_description = NewRecord.oppo_description +"- cloned";
NewRecord.oppo_stage = "Lead";
NewRecord.SetWorkflowInfo("Opportunity Workflow", "Lead");
 
NewRecord.SaveChanges();

//Redirects to List of Opportunities 
Response.Redirect(CRM.URL(184));
%>