JavaScript to set field value on fields in different sections

Comments

5 comments

  • Avatar
    Lucas Drege

    hi Darci,

    Please take a look at this documentation link, it should achieve what you are after.

    https://documentation.agilepoint.com/00/appbuilder/cloudjsSetFieldValue.html 

     

    Lucas

  • Avatar
    Darci Fluit

    I tried using:

    var options = {};
    options.fieldId = 'TextBox1'; // individual control
    options.value = 'Hello World';

    Inside my function but it didn't seem to work. Do you have to call out the section in order to set the field values of the fields in different sections?

    What I have above is working just not on the different sections on the form.

  • Avatar
    Lucas Drege

    Hi Darci,

    It looks like there are some pieces missing to your JS.

    Please add:

     

    eFormHelper.setFieldValue(options, function (result) //helper method to set the form field value in eForms

      {

      if (result.isSuccess) //check if is success

        {

        console.log(result.data); //logs the data holds empty object

        }

      else

        {

        console.log(result.error); //logs the error

        }

    });

     

    If this doesn't work, please raise a support ticket and we will ensure the right resources assist you.

    Lucas

  • Avatar
    Darci Fluit

    That worked using the code below.

    function BSATriageApp(){
      document.getElementById("EPSCGate").value = "3 - Sizing Analysis Review"; //first part

      var options = {}; //second part
    options.fieldId = 'BSATriageApprover'; // individual control
    options.value = 'Proceed';

    eFormHelper.setFieldValue(options, function (result)
      {
      if (result.isSuccess) //check if is success
        {
        console.log(result.data); //logs the data holds empty object
        }
      else
        {
        console.log(result.error); //logs the error
        }
      });}

    I'm using a button to execute the code and the first line works for the fields that are on the same page/section of the form as the button and the second part of the code works for fields that are on a different page/section of the form from the button.

    The first one seems much cleaner and simpler, any idea why that same line of code doesn't work for different sections of the form?

  • Avatar
    Karl Makatenas

    The first part works for form controls which are currently rendered.  Only the current section of a form has any rendered controls, so to access controls which are not on the current page, you need to use AgilePoint's helper functions.

Please sign in to leave a comment.