Using multiple AddEntryGroup within a DataPageNew class

1 minute read time.

There was a post recently on within the forums that discussed an a problem a partner was having with building a compound screen using the DataPageNew class


public class newOppo : DataPageNew 
{ 
public newOppo() 
: base("opportunity", "oppo_opportunityid", "opportunitywebpicker") 
{ 
AddEntryGroup("opportunitydetailbox"); 
AddEntryGroup("opportunitystatusbox"); 
} 
}

If you use just the code above you'll find that 2 opportunity records are created (with the same oppo_createddate).

The first is an opportunity record that contains the data contained in the opportunitywebpicker screen and opportunitystatusbox screen - BUT the data in the opportunitydetailbox is left NULL.

The second record is an opportunity record that contains the data contained in the opportunitydetailbox and the opportunitystatus box screen - BUT the data in the opportunitywebpicker is left NULL.

This is actually a known issue and the code that you will need to use to fully populate the record is shown below. This uses the BeforeSave override.

Note: Only one record is created as should be the case.


    public class AddOppo : DataPageNew
    {
        /* Constructor needs EntityName, IdField and ScreenName 
        */
        public AddOppo()
            : base("opportunity", "oppo_opportunityid", "opportunitywebpicker")
        {
            AddEntryGroup("opportunitydetailbox", Metadata.GetTranslation("tabnames", "details"));
            AddEntryGroup("opportunitystatusbox", Metadata.GetTranslation("tabnames", "status"));
        }
 
        public override void BeforeSave(EntryGroup screen)
        {
            if (this.Id > 0)
            {
                Record newRec = FindRecord(EntityName, this.IdField + " = " + Id.ToString());
                screen.Fill(newRec);
            }
 
        }
 
        public override void BuildContents()
        {
            SetContext("new");
            EntryGroup webpickerscreen = EntryGroups[0];
            webpickerscreen.Title = Metadata.GetTranslation("webpicker", "for");
            base.BuildContents();
        }
        
    }