Basic Code Structure of an Add or Insert Page

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Basic Code Structure of an Add or Insert Page

  • Comments 3
  • Likes
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'))
}
Comments
  • 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!

  • Michele

    Q:  If the field is included in the opportunitydetailbox, there is no further action required to create the opportunity record?

    A: Correct.

    Q: if the values are displayed on the screen, I only need the block and the record.  Am I understanding that correctly?

    A: You are.

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

    A: Yes.  See:  community.sagecrm.com/.../example-of-a-complex-screen-editing-multiple-records-in-asp-using-the-sage-crm-6-2-coding-name.aspx

  • Jeff...

    Sorry for the delay in posting back.  The information that you provided worked perfectly for me.

    Thank you!!!