I have two buttons "Save and Submit". The Save button, save the form in List without sending an e-mail to Approve. This form has 10 required fields. If I don't fill this required fields when I click in save button the form doesn't validate if the fields are fill or not....
I'm using rules and Custom Code:
public void btnSave_Clicked(object sender, ClickedEventArgs e)
{
WriteEventLog("Submitting the form");
// If the submit operation is successful, set
//e.CancelableArgs.Cancel = false;
// Write your code here.
requestID = 0;
filename = "";
requestStatus = "Draft";
// fetch the form name
String formname = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:formName", this.NamespaceManager).Value;
String currentYear = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:EventDetails/my:requestYear", this.NamespaceManager).Value;
String shortName = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:EventDetails/my:shortsubject", this.NamespaceManager).Value;
String eventDate = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:EventDetails/my:event_date", this.NamespaceManager).Value;
String now = DateTime.Now.ToString();
if (this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:fileName", this.NamespaceManager) != null)
{
filename = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:fileName", this.NamespaceManager).Value;
}
// Fetch the next ID
XPathNavigator idnavigator = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:requestID", this.NamespaceManager);
if (idnavigator != null)
{
requestID = fetchNextID(formname, currentYear);
idnavigator.SetValue(requestID.ToString());
}
filename = "Events--" + requestID.ToString("000");
this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:fileName", this.NamespaceManager).SetValue(filename);
this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:requestStatus", this.NamespaceManager).SetValue(requestStatus);
WriteEventLog("All data is ready!");
try
{
FileSubmitConnection fc = DataConnections["Main submit"] as FileSubmitConnection;
fc.Execute();
WriteEventLog("Form has been submitted");
}
catch (Exception ex)
{
WriteEventLog(ex.Message);
}
}
}
Rules:
Close the form -> When the button is clicked.
How can I do validate the required fields with the code? I cannot add the rule "Validation" in Button.