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

Hints, Tips and Tricks

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

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

  • Comments 18
  • Likes

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");
}
%>
 

 

Comments
  • Hi Jeff,

    helpful work. There are some interesting things inside.

    Christian

  • Hi Jeff,

    Thanks for the great work. But i am facing one problem in this, i have created the workflow same as you told in this example, but for some reason "New" button is not showing on Project Roles List Screen. What can be the problem for that ?

    Faraz

  • Thanks anyway, its resolved. Really it helped me alot

  • Hi Faraz,

    I am running into the same problem in that the New Button is not showing up for me on the Project Roles List.  I have double checked all Workflow rules and that the Workflow is enabled.  Can you tell me how you resolved?

    Thanks,

    Scotty Chapman

    Senior CRM Engineer

    Blytheco, LLC

    www.blytheco.com

    schapman@blytheco.com

  • Hi Faraz,

    Never mind - got it figured out. :)

  • Faraz and Scotty,

    How did you resolve this issue? Im having exactly the same problem

    Danny Owen

    CRM Consultant

    danny.owen@datelgroup.com

  • Sorted

    ta

  • Hello gyus

    This article is great but I still have a problem. In the workflow, I'd like to call a basic rule, but still have a 403.14 error message. I've tried many type of rule but I can't fix it

    Any idea ?

    Stan

  • 403.14 I thought was more of an issue with browsing folders on IIS.   (c.f. support.microsoft.com/.../en-gb)  Could you please create a new question in one of the forums and list the steps you have tried until you get to this problem.

    Thanks

  • pls could you show us how to accomplish this in .Net. Thanks

  • I mean using the .Net API. Thanks

  • Hi Jeff

    in following steps in your post I understood that I can't find the Project entity in the list of entities that are available for Search Entity field in adding Search Select Advanced in ProjectRoles secondary entity. What should I do?

  • Did you create the Project entity using the Advanced Search Select?

  • 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

  • Hi Everybody,

    hi Jeff,

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