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:
<!-- #include file ="../sagecrm.js"-->
<%
var strKeyID= "proj_projectid";
var Id = new String(Request.Querystring(strKeyID));
if (Id=="undefined")
{
Id = new String(Request.Querystring("key58"));
}
var intRecordId = 0;
if (Id.indexOf(",") > 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:
<!-- #include file ="../sagecrm.js"-->
<%
var strKeyID= "key58";
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 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:
<!-- #include file ="../sagecrm.js"-->
<%
//This is used in pages which are linked to from list custom jump.
var strKeyID= "prro_projectroleid";
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;
}
//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");
}
%>