Support and Training
Follow

Executing MetaScripts Based on Field Naming Conventions

By using a Regular Expression in MetaScript, you can watch a field or group of fields and trigger the execution of a specific script when a specific field has been edited. For example, suppose you have series of fields whose names contain “30Days” and “60Days” and you only want MetaScript to update a last edited date field when one of the “30Days”  fields are edited but should not execute when the “60Days” fields are edited. This task can be accomplished by setting up a loop with a regular expression that looks for “30Days”. 

The following MetaScript example looks for "30Days" to be contained in the name of the fields being modified on the form. When it encounters a field that contains "30Days" in it's name, it executes another MetaScript function.

//@version "2.0" 
 
Form.addEventListener("elementChanged", fChanges); 
 
function 
fChanges(e) 
var field = e.targetName; 
if(/30Days/.test(field)) 
Day30Completed(); 
 
function 
Day30Completed() 
 
SetField("CompletedBy30Days", LoggedInUser().Name); 
SetField("Date30Days", ServerDate()); 
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments