How to get a field value inside subform using JQuery or JavaScript?

Comments

5 comments

  • Avatar
    Nadia Segura

    The above works for me too, however the JavaScript methods are very useful as well, a bit confusing at the beginning but once you understand it is easy to implement, refer to getFieldValue method from link below

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

     

    This is how I used it:

     

    var cValue=GetControlValue({"fieldId":"SubFormName/ControlName"});

     

    function GetControlValue(ctrlName) {
     var ctrlVal ="";

    eFormHelper.getFieldValue (ctrlName, function (res) {
      if (res.isSuccess) { //check if is success   
              console.log(res.data); //logs the data holds the found control's value   
              ctrlVal = res.data;                 
            } else { console.log(res.error); }//logs the error          
        });

    return ctrlVal;

    }

    1
    Comment actions Permalink
  • Avatar
    Scott Bennett

    Not as straight forward as you would like. I actually get the value from the subform based on a button click where it uses a value in the subform to pop up a window of information. The button does not have a JS call in it but rather a rule where you can access [this]

    In the rule this is the method:

    btnAPS(this)

    JS required (ASAppID is the element name of the value in the subform that I want to use):

    function btnAPS(ctrl) {
    try {
    console.log ('Enter the app sts log function',ctrl);
    var val = GetSubFormControlStringValue(ctrl,'ASAppID');
    console.log('Application ID: ', val);
    window.open(NotifyAppCustom.UrlConstants.FormsAndPortal.APCSubmitForm+'&AppID='+val,'Application Log','height=600,width=800');
    } catch (e) {
    alert(e);
    }
    }

    and this is how to get the value from the subform:

    function GetSubFormControlStringValue(ctrl,controlName) {
    console.log ('Enter GetSubFormControlStringValue function');
    console.log ('ctrl: ',ctrl);
    console.log ('controlName: ',controlName);
    var val = $(ctrl).parents(".subFormContentRowChildWrapper").find("[id^='" + controlName + "']").val();
    console.log ('val: ',val);
    return val;
    }

    0
    Comment actions Permalink
  • Avatar
    SRL Support Team

    Hi,

    thanks a lot.

    In meanwhile, I found that the following syntax works too.

    $("[controlholdername ='+ controlName +']").find("input[id*='+ controlName +']").val();

    Marina

     

     

    0
    Comment actions Permalink
  • Avatar
    SOURAV DAS

    Hi All,
     For me the above methods did not work out. I have another solution 

    1.  To access any element in any section( which is not in subform )
       $(AllFieldsReference['INTERNALFIELDNAME'].querySelector('#INTERNALFIELDNAME ')).val();
    2.  To access any element inside a subform( which can be on any section )
       
      $(AllFieldsReference['INTERNALSUBFORMNAME '].querySelector('[id^="#INTERNALSUBFORMFIELDNAME "]')).val();


    Thanks
    Sourav

    0
    Comment actions Permalink
  • Avatar
    Leandro de Oliveira Fernandes

    Thanks Nadia Segura

    0
    Comment actions Permalink

Please sign in to leave a comment.