Adding a Link to the Notes table for a Custom Entity using the COM ASP API

Hints, Tips and Tricks

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

Adding a Link to the Notes table for a Custom Entity using the COM ASP API

  • Comments 9
  • Likes
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'));
}

Comments
  • Clicking on the link on the Note List after the creation of new note using code above gives AccessViolation error.  Any Ideas?

  • I have updated this article to include the code that will allow easy editing of Notes for a custom entity.

  • Hi Jeff,

    i have tried to impliment this solution on a custom entity. All works ok except when i click on an existing note to edit it CRM goes into the company context. My context look like this

    Company

    CompanyProduct (my custom entity)

    It stays in the contect of CompanyProduct until i try to edit a note and it Jumps UP into the context of the Company?

    I know this has something to do with the JumpAction but don't know how to fix this. Any ideas?

    thanks

  • Hi Jeff

    I have also used this code, and it is giving me access violation error still when i try to edit the note. Any Ideas ?

  • Can any one here please tell me how to solve this error... as I am still getting access violation error when i try to edit the note

  • and in editnote.asp what is MyGridColBlock... since i was getting the error for the same and changed it to notelist...

  • The only way I could get the hyperlink to noteEdit.asp to work was to create a new NotesList list based on vNotes and set the hyperlink to Custom Jump - specifying my asp page (dont forget the subfolder, if your asp file for noteEdit is in a sub folder of Custom Pages). Also change the CRM.GetBlock statement in notesList.asp to reference your new block.

  • Hello,

    Please, I can not make the link to go to the page I have a problem noteedit from the object "myGridColBlock"

    thank you

  • Abdel

    What version of Sage CRM are you using?  In later versions of Sage CRM e.g. Sage CRM v7.1 the Advanced Customization Wizard creates the link to the notes pages that you need.