using the form.GetField("fieldName") to access fields
Hi
I am writing a form where depending ion the type, different fields are valid. I have a List of field names that must have a value. I'd like to write a script something like below to vaildate the form
public static bool ValidateForm( ClientForm form)
{
List required = getRequiredFieldlist(form.Local.memrequiredFields); // call to split mem into list of req fields.
for (int i = 0;i < required.Count; i++)
{
if (form.GetField("txtLocation").DataValue == "")
{
return false;
}
}
return true;
}
This causes a compile error. I have tried
form.GetField<Metastorm.Runtime.Types.Text>("txtLocation");
but this doesn't work either.
Any thoughts?
Graham Field
Comments
-
You should pass the Business Object itself in, and use the values from that.
If you do not know what the the fields are (unlikely given you are doing validation), there are some examples in our > Process Mapping Library < that do this. I am sure there are a few passing in Business Objects too.
0 -
I have tried the Business object, but you can only access the properties of the fields. It doesn't appear to have a method for getting the datavalue of a field by passing in a string value of the required parameter.
I've run the debugger and found the GetField method actually runs through a set of if statements checking each variable in turn, then returns the variable if there is a match. However, this method associated with the form object doesn't appear to be accessible from the server scripts when passing in the form.
cheers
Graham
0 -
Why do you need to do this?
0 -
If you look in our library, you will find a function the 'Database' server script like so:
public static bool SelectRecord ( [Alias("Grid BO")] [Description("the Business Object for the Grid")] Metastorm.Runtime.Core.Mbo.Query qbo, [Alias("Current")] [Description("the 'Current' form object")] Metastorm.Runtime.Core.Forms.Form mf ) { ProcessContext pc = new ProcessContext(); DataSet ds = qbo.Read(); DataTable dt = ds.Tables[0]; DataColumnCollection dcc = dt.Columns; for ( int c = 0; c < dcc.Count; c++ ) { if ( mf.GetField( dcc[c].ColumnName ) != null ) { mf.FormMBO.SetField( dcc[c].ColumnName, pc.UserInput[c].Value ); } } return true; }
I think this is along the same lines as you want. Look at the loop and see how I get the form field value. The object to pass in (ignoring the BO for this requirement) is the object named "Current".
This is only really needed if, as in this case, you have no idea what the form contains (this being a generic reusable function). Typically you would not need to do this as you will know what teh variables are. If you want to have validation criteria stored in a table and parsed at run time, perhaps this would be needed, however.
0
Categories
- All Categories
- 123 Developer Announcements
- 54 Articles
- 154 General Questions
- 149 Thrust Services
- 57 Developer Hackathon
- 37 Thrust Studio
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 918 Core Messaging
- 84 Digital Asset Management
- 9.4K Documentum
- 33 eDOCS
- 190 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 10 XM Fax
- Follow Categories