Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

How to filter a web form static element using a form variable

wpomeroy
Level 2
Level 2

I am trying to allow a user to define a local variable in a web form and then pass that variable (offer label, start date, end date) into a table (list with group) in order to filter the table by the variable.  It seems like this should exist in the UI but i can't find a way to align the table fields with the variables.  Does anyone know a way to accomplish this either in the web form interface or via JS?

variables web apps web forms
1 Accepted Solution
MarcelSzimonisz
Correct answer by
Community Advisor
Community Advisor

hello @wpomeroy ,

turn on the _debug mode and see the web app context.

 

in general if you create the "Page (v5 compatibility)" with questions the xpath to that field should be:

 

ctx.webAppLogRcpData.your_input_name;

 

Also you have to make sure the survey option is checked in advanced properties of the web app:

image.png

 

if your form is ready with variable you want to save add Script activity and add in it logError() to stop processing and to show your web app context variables it will look similar to this:

<ctx lang="en" score="0" date="2020-05-06T07:50:23Z" _target="web" webApp-id="88878798798798" origin="neolane" _folderModel="nmsRecipient">
...
...
  <vars>
     <my_context_var>your context variable</my_context_var>
  </vars>
  <webAppLogRcpData>
     <your_input_name>
          value
      </your_input_name>
   </webAppLogRcpData>
</ctx>

 

Marcel

View solution in original post

3 Replies
MarcelSzimonisz
Correct answer by
Community Advisor
Community Advisor

hello @wpomeroy ,

turn on the _debug mode and see the web app context.

 

in general if you create the "Page (v5 compatibility)" with questions the xpath to that field should be:

 

ctx.webAppLogRcpData.your_input_name;

 

Also you have to make sure the survey option is checked in advanced properties of the web app:

image.png

 

if your form is ready with variable you want to save add Script activity and add in it logError() to stop processing and to show your web app context variables it will look similar to this:

<ctx lang="en" score="0" date="2020-05-06T07:50:23Z" _target="web" webApp-id="88878798798798" origin="neolane" _folderModel="nmsRecipient">
...
...
  <vars>
     <my_context_var>your context variable</my_context_var>
  </vars>
  <webAppLogRcpData>
     <your_input_name>
          value
      </your_input_name>
   </webAppLogRcpData>
</ctx>

 

Marcel

View solution in original post

Manoj_Kumar_
Community Advisor
Community Advisor

Hello @wpomeroy ,

You can define your variable in the webApp properties and then you can updated the values of the variable by Javascript.

manojk62306941_0-1588780145289.png


Once you have declared the variable in the webApp proerpties then you can use the javascript code to update the variable.

document.controller.setValue('/ctx/vars/VARIABLE_NAME','VARIABLE_VALUE');

 

wpomeroy
Level 2
Level 2

Thank you for the response. I had already defined the variables and have fields in the page writing to the variables.  I am struggling with the JS piece within the page to then define the table based on the form response.  Is there a place within the list to call the variable or are you suggesting updating the JS on the code tab of the Web App?

wpomeroy_0-1588785926660.png

if( (ctx.vars.OfferLabel == undefined || NL.String.trim(ctx.vars.OfferLabel.toString()).length == 0) )
{
// The context is empty for this non hidden input =&gt; try its post value!
var strPostValue = serverForm.request.getParameter("vars_OfferLabel")
if( strPostValue.length > 0 )
ctx.vars.OfferLabel = strPostValue
}

if( (ctx.vars.OfferStartDate == undefined || NL.String.trim(ctx.vars.OfferStartDate.toString()).length == 0) )
{
// The context is empty for this non hidden input =&gt; try its post value!
var strPostValue = serverForm.request.getParameter("vars_OfferStartDate")
if( strPostValue.length > 0 )
ctx.vars.OfferStartDate = strPostValue
}

if( (ctx.vars.OfferEndDate == undefined || NL.String.trim(ctx.vars.OfferEndDate.toString()).length == 0) )
{
// The context is empty for this non hidden input =&gt; try its post value!
var strPostValue = serverForm.request.getParameter("vars_OfferEndDate")
if( strPostValue.length > 0 )
ctx.vars.OfferEndDate = strPostValue
}

}

wpomeroy_1-1588786157669.png