Automate

 View Only
  • 1.  Resetting Evolve Form Fields

    Posted 02-27-2024 14:53

    Hi all,

    I am trying to implement a rule to reset all form fields to default values if a form is routed through a particular step in a workflow. I would like to avoid having to create a rule that needs to call out every specific field if possible.

    I have tried using a custom rule using document.getElementByID("formname").reset() but haven't been successful. Disclaimer: I am not well-versed in javascript so perhaps there is a different method that is more appropriate? 

    If anyone has any ideas or similar functionality in your solutions I would love to hear them. Thanks in advance!



    ------------------------------
    Alex Kuligowski
    Data Governance
    Leprino Foods
    Denver, CO
    ------------------------------


  • 2.  RE: Resetting Evolve Form Fields

    Employee
    Posted 02-28-2024 02:49
    Edited by Hammad Naeem 02-28-2024 02:50

    Hi Alex,

    use code mentioned below if your form has only non repeating fields with default Values on the form.

    ---------------------------- // code starts here

    dvfields = renderer.formModel.getForm_DataByProperty(renderer.formModel.Schema, "defaultValue", null, true);
    for (i = 0; i < dvfields.length; i++) {
    if (dvfields[i].defaultValue.length == 0) continue;
    var element = $j("[data-link='" + renderer.formModel.formatInputBinding(dvfields[i].binding) + "']");
    if (typeof dvfields[i].defaultValue !== 'undefined' && dvfields[i].defaultValue !== null) {
    $form.setValue(dvfields[i].binding,dvfields[i].defaultValue)
    }
     
    }
    ------------------------------- // code ends here
    Use code mentioned below if your form has both repeating and non repeating fields with default values :
    -------------------------------- // code starts here
    dvfields = renderer.formModel.getForm_DataByProperty(renderer.formModel.Schema, "defaultValue", null, true);
    for (i = 0; i < dvfields.length; i++) {
    if (dvfields[i].defaultValue.length == 0) continue;
    var fpath = dvfields[i].binding;
                              if(fpath.indexOf("Repeating_Content")<0)
      {
    if (typeof dvfields[i].defaultValue !== 'undefined' && dvfields[i].defaultValue !== null) 
    {
                $form.setValue(fpath,dvfields[i].defaultValue)
                }
      }
      else
      {
      var tblLength = count(fpath);
      for(var j = 0;j<tblLength;j++)
      {
    var fPathWIndex =  fpath.substring(0,fpath.indexOf("Repeating_Content")+17)+'['+j+']'+ fpath.substring(fpath.indexOf("Repeating_Content")+17);
    if (typeof dvfields[i].defaultValue !== 'undefined' && dvfields[i].defaultValue !== null) 
    {
    $form.setValue(fPathWIndex,dvfields[i].defaultValue)
    }
      }
      }
     
    }
    ------------------------------------------ // code ends here
    You can apply a custom rule either on view load or on a button click or whatever best suits your requirement.
    Hope this helps.
    Regards



    ------------------------------
    Hammad Naeem
    Precisely Software Inc.
    ------------------------------



  • 3.  RE: Resetting Evolve Form Fields

    Employee
    Posted 02-28-2024 20:20

    Wow Hammad - that's fabulous!



    ------------------------------
    Sigrid Kok
    Precisely Software Inc.
    ------------------------------



  • 4.  RE: Resetting Evolve Form Fields

    Posted 03-06-2024 14:47

    Thanks so much Hammad, this is very helpful. I am working with the custom rule that you provided, and had a follow up question.

    Based on some functionality I implemented in the parent form this is going into, I need to now also reset fields which might not have default values defined. Examples include drop-down selections by the user where there is no option to use the --Select-- as a default.

    Is there a tweak I could make to essentially clear out any form field on the form, whether it has a default value called out or not? Or conversely, can I define a default "blank" value for fields which will not be pre-populated?

    Thanks again for your help!



    ------------------------------
    Alex Kuligowski
    Data Governance
    Leprino Foods
    Denver, CO
    ------------------------------



  • 5.  RE: Resetting Evolve Form Fields

    Employee
    Posted 03-07-2024 09:22

    Hi Alex,

    To reset the fields with no default values use code below :

    ------------------------- // code starts here

    var AllFields = renderer.formModel.getForm_DataByProperty(renderer.formModel.Schema, "binding", null, true);
    for (i = 0; i < AllFields.length; i++) {
    $form.setValue(AllFields[i].binding,'') 
    }
     
    dvfields = renderer.formModel.getForm_DataByProperty(renderer.formModel.Schema, "defaultValue", null, true);
    for (i = 0; i < dvfields.length; i++) {
    if (dvfields[i].defaultValue.length == 0) continue;
    if (typeof dvfields[i].defaultValue !== 'undefined' && dvfields[i].defaultValue !== null) {
    $form.setValue(dvfields[i].binding,dvfields[i].defaultValue)
    } 
    }
    -----------------------------------// code ends here
    Above code resets the value for all fields to empty and then resets the default value fields to their default values.
    Hope this helps.
    Regards


    ------------------------------
    Hammad Naeem
    Precisely Software Inc.
    ------------------------------



  • 6.  RE: Resetting Evolve Form Fields

    Posted 03-07-2024 14:23

    Thanks so much Hammad, this worked perfectly. Much appreciated!!



    ------------------------------
    Alex Kuligowski
    Data Governance
    Leprino Foods
    Denver, CO
    ------------------------------