1
0
-1

Hi experts ¡

   I have an aproval procees with three activities, it use a workflow variable named status that must change in every activity, in the first activity i did define a field where the user must stablish a percent  , regarding this porcent i would like that in the second activity the user fill a field to pass to the last activitie.   

Someone could share an example of how can i apply this control on the form in order to enble the SAVE button only if the user fill a field with a value  equal to the percent stablished in the previus activity?

 

  1. Fabian Barrera

    Hi, I think using the validation in a calculation field I can control the pass to the next activity, however, I did a test and trying to use this bean shell code and but I am not sure about the sample: I can´t indetify how the value of the second field in the form, which the validator will compare, if the code can compare both fields and they are not equal (in value) so the activity can´t continue import java.util.Arrays; import org.joget.apps.app.service.AppUtil; import org.joget.apps.form.model.Element; import org.joget.apps.form.model.Form; import org.joget.apps.form.model.FormData; import org.joget.apps.form.service.FormUtil; public boolean validate(Element element, FormData formData, String[] values) { boolean result = true; //get field 1 value from form data object String field1Id = "total_prop"; // FB: It is the first field in the form that i would like compare Form form = FormUtil.findRootForm(element); Element field1 = FormUtil.findElement(field1Id, form, formData); if (field1 != null) { //get value of field 1 String[] compareValues = FormUtil.getElementPropertyValues(field1, formData); //compare the value of field 2 and field 1 are equals if (!Arrays.equals(values, compareValues)) { String id = FormUtil.getElementParameterName(element); formData.addFormError(id,"Debe Completar el Monto a Pagar"); result = false; } } else { //ignore if the field 1 not exist } return result; } window.alert(field1); //call validate method with injected variable return validate(element, formData, values);

  2. Anders

    Hi, if this is bean shell code, then it is executed server side. In this case the window.alert in your code would throw an error since that looks like javascript code.

CommentAdd your comment...

1 answer

  1.  
    1
    0
    -1

    Hi, there is a sample you can base on in Bean Shell Programming Guide#UseasFormValidator.

    1. Fabian Barrera

      Hi Anders, please could you explain better how work this code? For example: Which part i must use to refer to field in the form that i need take to compare with my calculation field ? mport java.util.Arrays; import org.joget.apps.app.service.AppUtil; import org.joget.apps.form.model.Element; import org.joget.apps.form.model.Form; import org.joget.apps.form.model.FormData; import org.joget.apps.form.service.FormUtil; public boolean validate(Element element, FormData formData, String[] values) { boolean result = true; //get field 1 value from form data object String field1Id = "field1"; Form form = FormUtil.findRootForm(element); Element field1 = FormUtil.findElement(field1Id, form, formData); if (field1 != null) { //get value of field 1 String[] compareValues = FormUtil.getElementPropertyValues(field1, formData); //compare the value of field 2 and field 1 are equals if (!Arrays.equals(values, compareValues)) { String id = FormUtil.getElementParameterName(element); formData.addFormError(id, "Value not equal!!!!"); result = false; } } else { //ignore if the field 1 not exist } return result; } //call validate method with injected variable return validate(element, formData, values);

    CommentAdd your comment...