This article discusses how the Notes table is linked to the parental record using the idea of the ForeignTableID and ForeignID fields.
Below you can see that I have added the Notes table to a Custom Entity (Project).
There are 3 main screens that we need to cover. The idea of the List screen (above), the insert screen for adding new Notes to the Custom Entity, and the Edit screen that would allow the review of the created record.
The file names assumed in this example
- noteslist.asp
- addnote.asp
- noteedit.asp
Using the information about the structure of the Notes table and the information in the previously mention articles that show how to structure basic page then we can now easily construct the code for the insert and listing tasks.
Example Code to List Notes associated with Custom Entity
//page assumed to be called noteslist.asp
var CustomEntityName = 'Project';
var customtablerecord = CRM.FindRecord("custom_tables","bord_caption='"+CustomEntityName+"'");
var ForeignTableId = customtablerecord.bord_tableid;
var ForeignId = Request.QueryString('key58');
var CallASPButton = CRM.Button('New','newtask.gif', CRM.Url('addnote.asp'));
var notelist = CRM.GetBlock('notelist');
//code to add reference to edit page
with (myGridColBlock)
{
JumpAction= 430;
//only relevant if Custom jump
CustomActionFile = "noteedit.asp";
CustomIdField = "note_noteid";
}
notelist.AddButton(CallASPButton);
var Arg = 'note_foreigntableid='+ForeignTableId + ' and note_foreignid = '+ ForeignId;
CRM.AddContent(notelist.Execute(Arg));
Response.Write(CRM.GetPage(CustomEntityName));
Example Code to Add Note to Custom Entity
if (CRM.Mode==View)
{
CRM.Mode = Edit;
}
var CustomEntityName = 'Project';
var customtablerecord = CRM.FindRecord("custom_tables","bord_caption='"+CustomEntityName+"'");
var ForeignTableId = customtablerecord.bord_tableid;
var ForeignId = Request.QueryString('key58');
var myRecord = CRM.CreateRecord('Notes');
myRecord.note_foreigntableid=ForeignTableId;
myRecord.note_foreignid= ForeignId;
var myBlock = CRM.GetBlock('noteboxlong');
myBlock.Title= CRM.GetTrans('Tabname','Note');
CRM.AddContent(myBlock.Execute(myRecord));
Response.Write(CRM.GetPage(CustomEntityName));
if(CRM.Mode==Save)
{
Response.Redirect(CRM.URL('noteslist.asp'));
}
Example Code to Edit Note for Custom Entity
if (CRM.Mode==View)
{
CRM.Mode = Edit;
}
var CustomEntityName = 'Project';
var strKeyID= "note_noteid";
var Id = new String(Request.Querystring(strKeyID));
var intRecordId = 0;
if (Id.indexOf(",") > 0)
{
var Idarr = Id.split(",");
intRecordId = Idarr[0];
}
else if (Id != "")
{
intRecordId = Id;
}
var Arg = "Note_noteid="+intRecordId;
var myRecord = CRM.FindRecord('Notes', Arg);
var myBlock = CRM.GetBlock('noteboxlong');
myBlock.Title= CRM.GetTrans('Tabname','Note');
CRM.AddContent(myBlock.Execute(myRecord));
Response.Write(CRM.GetPage(CustomEntityName));
if(CRM.Mode==Save)
{
Response.Redirect(CRM.URL('noteslist.asp'));
}