Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Setting a hidden Record Producer field's value using dom manipulation in service portal

aditya_agrawal
ServiceNow Employee
ServiceNow Employee

Hello,
I am unable to access the value of a hidden variable field named `captcha` in the record-producer script using producer.captcha, it's showing as empty.
I am setting it's value using javascript in the frontend through this script. : 

document.querySelector('input[name=captcha]').value = grecaptcha.getResponse();

This value is set by another widget (custom captcha widget) which renders alongside the record producer. 
I have verified that the input value is being set in the frontend, but I don't get it why the value is showing empty in the record producer script.

Any help/suggestions please.
Thank You

7 REPLIES 7

@aditya_agrawal 

Can you share your complete business requirement?

you cannot set variable value from record producer script

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

aditya_agrawal
ServiceNow Employee
ServiceNow Employee

@Ankur Bawiskar 
My business requirement is that I want to validate a captcha on the server side, for this I would need the captcha response, which is provided by the grecaptcha.getResponse(), where grecaptcha comes from the google recaptcha widget and is available in frontend. 
For this, I am trying to use a hidden form field, and send the captcha response along with the form.
I am not setting the value from record producer script, instead from the frontend script of the custom captcha widget:  

<div ng-if="!data.logged_in"> 
<body>  
  <div class="g-recaptcha" data-sitekey="{{data.sitekey}}" data-callback="setCaptchaResponse" data-expired-callback="setCaptchaResponse"></div>  
  <script src='https://www.google.com/recaptcha/api.js'></script>
  <script>
  function setCaptchaResponse(){
    document.querySelector('input[name=captcha]').value = grecaptcha.getResponse();
  }
  </script>  
</body>  
</div>

 
Regards
Aditya

@aditya_agrawal 

then do that validation in widget itself

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader