spacer
cornerspacercorner
Reply
Occasional Contributor
Graham Field
Posts: 9
Registered: 06-17-2010
0 Kudos

using the form.GetField("fieldName") to access fields

[ Edited ]

Hi

I am writing a form where depending ion the type, different fields are valid. I have a List<string> 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<string> 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

 

 

Esteemed Contributor
Jerome҉
Posts: 744
Registered: 05-18-2010
0 Kudos

Re: using the form.GetField("fieldName") to access fields

[ Edited ]

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.

Occasional Contributor
Graham Field
Posts: 9
Registered: 06-17-2010
0 Kudos

Re: using the form.GetField("fieldName") to access fields

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

 

 

Esteemed Contributor
Jerome҉
Posts: 744
Registered: 05-18-2010
0 Kudos

Re: using the form.GetField("fieldName") to access fields

Esteemed Contributor
Jerome҉
Posts: 744
Registered: 05-18-2010
0 Kudos

Re: using the form.GetField("fieldName") to access fields

[ Edited ]

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.

 

 

line spacer line
spacerFollow Metastorm on:
spacer Twitter YouTube Blog iTunes LinkedIn Metastorm Community Central, MC2
spacer Copyright © 2011 OpenText Corporation. All Rights Reserved.spacer About Metastormspacer Privacyspacer Legalspacer Site Mapspacer RSSspacer Contact Us
Microsoft Gold Certified Partner
Powered by Windows Azure
line spacer line