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'))
}
Parents
  • Jeff...

    If the field is included in the opportunitydetailbox, there is no further action required to create the opportunity record? I see the lines on how to set the values for fields not displayed on the screen. Therefore, I am assuming that if the values are displayed on the screen, I only need the block and the record. Am I understanding that correctly?

    Also, is it possible to use this same theory to insert records into different entities displayed on the same container.

    I know if have done inserts reading from an internal or external table into different entities. However, I am wondering if I can develop that same theory here from the screen.

    Any assistance you can provide would be greatly appreciated.

    Thank you!

Comment
  • Jeff...

    If the field is included in the opportunitydetailbox, there is no further action required to create the opportunity record? I see the lines on how to set the values for fields not displayed on the screen. Therefore, I am assuming that if the values are displayed on the screen, I only need the block and the record. Am I understanding that correctly?

    Also, is it possible to use this same theory to insert records into different entities displayed on the same container.

    I know if have done inserts reading from an internal or external table into different entities. However, I am wondering if I can develop that same theory here from the screen.

    Any assistance you can provide would be greatly appreciated.

    Thank you!

Children
No Data