How to Create a Secondary Entity for a new Custom Primary Entity

2 minute read time.

This article shows the steps that I went through to create a secondary entity that is a child of a Custom Primary Entity.

The business scenario that I imagined was that I had a new Primary Entity called Project that was created using the Advanced Customization Wizard.

I needed to create a secondary entity called ProjectRoles that would allow me to associate users with the project.

I added the table called ProjectRoles through the main interface. The table is not a child of companies or persons, but it is a child of users. I have also added a workflowid column as this will help me create the records in the interface.

Administration -> Advanced Customization -> Tables and Databases

Note: It is a good idea to call the description field "name" e.g. prro_name as this makes other features easier to implement especially if at some point in the future you wish to add this entity into the recent list.

I then updated the fields captions and added a new search select advanced field to link to the parent project entity.

I created an entry screen "ProjectRoleDetailBox".

I created a list "ProjectRolesList". For a production environment I would have based my list of a view rather than the table.

Note: I added a custom jump hyperlink to the "projectrolesedit.asp" which I added to the "project" folder created by the Advanced Customization Wizard.

Since the ProjectRole is to be used in the context of the Project entity, I added a Project Roles option to the Project tab group. This will call the "ProjectRolesList.asp" page which I added to the "project" folder.

I then created a workflow to be used for the ProjectRole entity. In my little example I only used a single primary rule and a simple state.

The primary rule calls an ASP page "projectrolesadd.asp" that I added to the "project" folder. The rule does not have workflow actions as when an ASP page is called by a workflow rule, any workflow actions are ignored.

Once I have entered the Meta Data I wrote the ASP pages.

ProjectRolesList.asp

The screen shot of the projectroleslist.asp is below:

The code I used is here:



 0)
{
   var Idarr = Id.split(",");
   intRecordId = Idarr[0];
}
else if (Id != "")
{
  intRecordId = Id;
}
 
var myBlock = CRM.GetBlock("ProjectRolesList");
var strURL=new String( Request.ServerVariables("URL")() + "?" + Request.QueryString );
myBlock.prevURL=strURL;
 
//Set Block to use workflow properties
with(myBlock)
{
  WorkflowTable = "ProjectRoles";
  ShowNewWorkflowButtons = true;
}
 
var Arg = "prro_projectid="+intRecordId;
CRM.AddContent(myBlock.Execute(Arg));
Response.Write(CRM.GetPage());
%>

ProjectRolesAdd.asp

The screen shot of the projectrolesadd.asp is below:



 0)
{
   var Idarr = Id.split(",");
   intRecordId = Idarr[0];
}
else if (Id != "")
{
  intRecordId = Id;
}
 
var myRecord = CRM.CreateRecord("projectrole");
myRecord.prro_projectid = intRecordId;
myRecord.SetWorkflowInfo("ProjectRole Workflow", "New Member");
 
var myBlock = CRM.GetBlock("projectroledetailbox");
myBlock.Title = CRM.GetTrans("tabnames","teammember");
 
if (CRM.Mode == View)
{
CRM.Mode = Edit;
}
 
CRM.AddContent(myBlock.Execute(myRecord));
Response.Write(CRM.GetPage());
 
if (CRM.Mode == Save)
{
Response.Redirect(CRM.URL("project/projectroleslist.asp")+" &T=project &proj_projectid="+intRecordId);
}
%>

ProjectRolesEdit.asp

The screen shot of the projectrolesedit.asp is below:



 0)
{
   var Idarr = Id.split(",");
   intRecordId = Idarr[0];
}
else if (Id != "")
{
  intRecordId = Id;
}
 
//Retrieve Record
var myRecord = CRM.FindRecord("projectroles","prro_projectroleid="+intRecordId);
var myBlock = CRM.GetBlock("projectroledetailbox");
myBlock.Title = CRM.GetTrans("tabnames","teammember");
 
if (CRM.Mode == View)
{
CRM.Mode = Edit;
}
 
CRM.AddContent(myBlock.Execute(myRecord));
Response.Write(CRM.GetPage("project"));
 
if (CRM.Mode == Save)
{
Response.Redirect(CRM.URL("project/projectroleslist.asp")+" &T=project");
}
%>

  • Hi Jeff,

    Thanks for the great article, but I just noticed one sentence you wrote in it:

    "The rule does not have workflow actions as when an ASP page is called by a workflow rule, any workflow actions are ignored."

    This is just exactly what I want to do. I want to send email when workflow status changes with custom asp pages. So I tried to add an email action but it didn't get triggered as you wrote.

    Does this mean that I have to send email inside asp page? like using Email Object?

    I want to avoid it since the email template is composed by another guy and I just want to send email using the template. The Email Object seems not to have such template importing mechanism, am I right?

    Regards

  • Hi Jeff,

    Thanks for the great article, but I just noticed one sentence you wrote in it:

    "The rule does not have workflow actions as when an ASP page is called by a workflow rule, any workflow actions are ignored."

    This is just exactly what I want to do. I want to send email when workflow status changes with custom asp pages. So I tried to add an email action but it didn't get triggered as you wrote.

    Does this mean that I have to send email inside asp page? like using Email Object?

    I want to avoid it since the email template is composed by another guy and I just want to send email using the template. The Email Object seems not to have such template importing mechanism, am I right?

    Regards

  • Ryiad

    Adding the delete button is easy. See the article community.sagecrm.com/.../adding-buttons-to-an-asp-page.aspx

    The delete feature should be added automatically.

    You will have to manage what happens once the record is deleted. Are you familiar with CRM.Mode?

  • Hi Everybody,

    hi Jeff,

    Thanks for the great work ,still code for delete in secondary entity can you help me

  • Hi Everybody,

    hi Jeff,

    I have the same Problem like some before me. The "New Button" is not in the Project Roles List. I have checked so many things. Can anybody tell me, how to resolve this problem, before I get cracy.

    Thank you for every help and Hint.

    Weber Stephan