Creating a Quick Entry Screen using the DataPageNew class

2 minute read time.

Below is some code that was written to allow records to be entered from the Company Summary screen. I have used cases here but this could be for any entity including custom entities.

The business scenario is

  • The customer would like to have a simplified way of creating records (e.g. case or project) direct from the company summary screen.
  • The customer has several custom dot net assemblies already in use within the company context.
  • The record (e.g. case or project) will be automatically linked to the Company and Person in context.
  • Depending on the data entered some 'correction' or automatic formatting of the data needs to be applied.
  • Once a record (e.g. case or project) has been entered the page needs to list the records.
  • A record (e.g. case or project) needs to be assigned to a workflow.

Note:

  • This example uses code that assumes you are using 6.2g onwards.
  • This is not a fully worked example and I have excluded the update status fields and the creation of a corresponding progress record.

Code:


using Sage.CRM.WebObject;
using Sage.CRM.Controls;
using Sage.CRM.Data;
using Sage.CRM.Utils;
 
namespace DeleteMeOppoList
{
    public class CreateCase : DataPageNew
    {
        /* Constructor needs EntityName, IdField and ScreenName 
        */
        public CreateCase()
            : base("cases", "case_caseid", "casedetailbox")
        {
            //this.SaveMethod = "RunDataPage";
            this.UseWorkflow = true;
            this.WorkflowName = "Case Workflow";
            this.WorkflowState = "Logged";
            this.UrlAfterSave = Url("185");
        }
 
        public override void BuildContents()
        {
            GetTabs("Company", "Cases"); // Force the tab Groups be highlighted
            base.BuildContents();
        }
 
        public override void AfterSave(EntryGroup screen)
        {
            Record recNewCase = screen.getRecord;
 
            string casePriority = Dispatch.ContentField("case_priority");
            if (casePriority == "High")
            {
                string caseDescription = Dispatch.ContentField("case_description");
                recNewCase.SetField("case_description", caseDescription.ToUpper());
            }
            recNewCase.SetField("case_primarycompanyid", int.Parse(GetContextInfo("company", "comp_companyid")));
            recNewCase.SetField("case_primarypersonid", int.Parse(GetContextInfo("company", "comp_primarypersonid")));
            recNewCase.SaveChanges();
        
            base.AfterSave(screen);
        }
    }
 
}

Notes

1) In the image below you can see that the "Quick Case" button is on the Company Summary screen.

You can also see that I have another Tab which is actually calling a Dot Net assembly.

The "Quick Case" button calls my dot net assembly. But the only Dot Net assembly in the Tab menu is "Brokered Oppos". And so by default when the button is pressed "Brokered Oppos" would be highlighted.

But I can control the Tab that should be displayed if I use the GetTabs overload that was introduced in Sage CRM 6.2g and Sage CRM v7.0 sp1

 
        public override void BuildContents()
        {
            GetTabs("Company", "Cases"); // Force the tab Groups be highlighted
            base.BuildContents();
        }

2) I have overridden the default AfterSave behaviour to allow me to include additional tasks.

AfterSave has the parameter passed to it "screen" which is the screen used in the constructor for the DataPageNew class.

We are able to use the property getRecord() to access the newly create record.

Data that is being passed into CRM from the screen can be accessed using the Dispatch.Contents() method.

The Data can then be corrected in anyway that you need, either manipulating the data or by setting values automatically for data not displayed on the screen.