Basic Code Structure of an Add or Insert Page

Less than one minute read time.
Here we can see the basic code structure for an Insert of a new Record expressed in ASP page code.

I have used here a new opportunity record but it really could be any record including tables in third-party databases. Please note the comments.

if(CRM.Mode ==View)
{
CRM.Mode = Edit;
}
var myBlock = CRM.GetBlock('opportunitydetailbox');
var myRecord = CRM.CreateRecord('Opportunity');

//set values for fields not displayed on screen
myRecord.oppo_stage= 'Lead';
myRecord.oppo_status= 'In Progress';
myRecord.oppo_primarycompanyid= CRM.GetContextInfo('Company','comp_companyid');
myRecord.oppo_primarypersonid= CRM.GetContextInfo('person','pers_personid');

//set workflow
myRecord.SetWorkflowInfo("Opportunity Workflow", "Lead");

CRM.AddContent(myBlock.Execute(myRecord));
Response.Write(CRM.GetPage());

if(CRM.Mode == Save)
{
//Redirect page where after the save
Response.Redirect(CRM.URL('customoppolist.asp'))
}