I think this has been asked before, but any years ago!
Is there any of resetting all the form variables, rather than having to copy and paste them into a new method to set them back to the original definitions?
Is there a command for this yet?
forms.test.controller.resetformvariables() ??? would be nice
You can write a simple (global) method for this since a form has an allvariables property that returns an array with your form variables.
Just iterate this array and set all variables to null (or another value).
function resetFormVars(formName)
{
var myForm = solutionModel.getForm(formName);
for (var i in forms[formName].allvariables) {
var formV = myForm.getFormVariable(forms[formName].allvariables[i]);
forms[formName].controller.setDataProviderValue(formV.name, formV.defaultValue);
}
}
Where formName is the name of the Form where this method is called.
formV.defaultValue doesn’t work properly (I think) because when the default value of a variable is null, it returns the string “NULL”
Ok, I have to modify the method:
function resetFormVars(formName)
{
var myForm = solutionModel.getForm(formName);
for (var i in forms[formName].allvariables) {
var formV = myForm.getFormVariable(forms[formName].allvariables[i]);
if(formV.defaultValue.toUpperCase() == 'NULL') {
forms[formName].controller.setDataProviderValue(formV.name, null);
} else {
forms[formName].controller.setDataProviderValue(formV.name, formV.defaultValue);
}
}
}
But… it’s no ok!! Again, with formV.defaultValue. When the default value is a string, formV.defaultValue return a string with single quotes: “‘default_value’”. So I have to modify again the method, like this:
function resetFormVars(formName)
{
var myForm = solutionModel.getForm(formName);
for (var i in forms[formName].allvariables) {
var formV = myForm.getFormVariable(forms[formName].allvariables[i]);
if(formV.defaultValue.toUpperCase() == 'NULL') {
forms[formName].controller.setDataProviderValue(formV.name, null);
} else {
//SI LA VARIABLE ES STRING, SERVOY SE EMPEÑA EN PONER UNAS COMILLAS, ASI QUE TOCA QUITARLAS
forms[formName].controller.setDataProviderValue(formV.name, utils.stringReplace(formV.defaultValue, "'", ""));
}
}
}