Hello,
I have a piece of code for Sage CRM 7.3 SP1 which doesn't preserve data after post-back when CRM validation fails.
Based on my analysis, I was able to retrieve data from the initialized entity after the fill method is applied but the method seems to pre-populate the entity rather than the screen itself.
This algorithm works for Sage CRM 7.2 but it doesn't work for 7.3
Could anyone help please?
public override void BuildContents()
{
try
{
// instantiate a member class
Member member = new Member();
// add HTML form
AddContent(HTML.Form());
// instantiate a HTML form and pass a form name to its constructor
EntryGroup egBoard = new EntryGroup("BoardNewEntry");
// assign a title to the HTML form. Retrieve the title from CRM translations
egBoard.Title = Metadata.GetTranslation("tabnames", "Board");
// get the mode value from a hidden textbox which allows value preservation across postbacks
string hMode = Dispatch.ContentField("HiddenMode");
// if the mode is set to 'Save'
if (hMode == "Save")
{
// if all user input is valid for the form
if (egBoard.Validate())
{
// do something
}
else // if the user input is invalid
{
// redraw the screen
RedrawEditMode(egBoard);
}
}
else // if the mode is set to nothing
{
// add an empty textbox with a name
AddContent(HTML.InputHidden("HiddenMode", ""));
// instantiate a HTML container/DIV
VerticalPanel vpMain = new VerticalPanel();
// set the width
vpMain.AddAttribute("width", "100%");
// make the form editable
egBoard.GetHtmlInEditMode();
// add the HTML form
vpMain.Add(egBoard);
// display the container
AddContent(vpMain);
// add button/s
AddButtons();
}
}
catch (Exception error)
{
this.AddError(error.Message);
}
// methods
private void AddButtons()
{
// to do : T header mode is inconsistent
string strPreviousPageURL = Url("Board/BoardFind.asp");
string strSaveURL = "javascript:document.EntryForm.HiddenMode.value='Save';";
AddSubmitButton("Save", "Save.gif", strSaveURL);
AddUrlButton("Cancel", "Cancel.gif", strPreviousPageURL);
}
private void RedrawEditMode(EntryGroup screen)
{
// add an empty textbox with a name
AddContent(HTML.InputHidden("HiddenMode", ""));
// instantiate a placeholder for values
Entity eBoard = new Entity("Board");
// fill the form with the retrieved record
screen.Fill(eBoard);
// make the form editable and display it
AddContent(screen.GetHtmlInEditMode());
// add buttons
AddButtons();
}
Any comments or suggestions are welcome. Thanks.