Form variable for building a running total in NWC

  • 21 August 2019
  • 8 replies
  • 3 views

Badge +2

I have a form that looks for responses to about 30 questions. Each question has a yes/no toggle. When the toggle is 'no' a drop-down appears (and is required) for the user to select 1, 2 or 3. This is controlled by a rule, with one rule for each question.

 

I am looking to capture the highest score applied as the user proceeds through the form. I have created a form variable (integer) and set '0' as the default value.

 

What I'd like to do is convert the selected score to a number, then test if it is > the value of the running score. If that test is true, then I set the running score to that value. If it is false, then the running score remains at the highest score previously logged. I can't find a way within the rule to adjust the value of my running score - am I missing something? 

 

Would be grateful for any suggestions, I'd like this cumulative score to be visible to the user before the form is submitted.

 

Thanks everyone.


8 replies

Badge

Just to clarify if a user inputs 1 on the first choice you want the running score to be 1. Then if the user inputs 2 on the second choice you want the running score to be 2 correct? because 2 >1. And so on and so forth if the user selects 3 for an answer on a subsequent choice control.

Badge +2
That is indeed correct, Joseph.

I am thinking I need to set a hidden field value with the variable and then re-set the variable value - which is currently defined as text because it's selected from a drop-down. So along the way I am anticipating there needs to be a convert to a number function. Just scratching my head how to do this before the form is submitted (if it were after, I know how to make the workflow do this).

Thanks
Badge +7

Well, you could create a form variable with a formula like this:

 

max(convertToNumber([Form].[Choice  single 1]),convertToNumber([Form].[Choice  single 2]),convertToNumber([Form].[Choice  single 3]))

 

Unfortunatly you cannot bind a form-variable to a field in the form, so the computed value will not be visible in the form, but it is available in the workflow.

Badge +2

Thanks for that, eiben - I now realise that I cannot do what I want. I was very much looking to have the result visible as the form is being completed, because it's a form to record observation of a safety procedure, and both the observer and the observed party are expected to sign indicating agreement. The exercise may take place in a location without network connectivity, so a workflow wouldn't execute until the observer returns to a location from where the form will be submitted.

 

I defined a variable exactly as you suggested but got stuck when I tried to set a rule for each question that would compare the score for that question with the running score variable and update a 'Maximum Score' field with the then-current value of the variable. 

 

I'll have to re-think the approach with the stakeholders.

 

The response, however is very much appreciated!

Badge +7

If you have real application/business logic, that has to be part of the form, then a Nintex Form might not be the best choice. You might have to consider using some other technologie to build the front-end and turn the workflow into a component-workflow, that can than be called from a web-frontend for example. This is quite easily and you could build a more complexe front-end using javascript and PWA technologies and leverage NWC for the processing of the collected values.

Badge +2
Thanks - I can see the sense in that, but not in this specific case. I think the business user will have to rely on eyeball technology and a manual entry. I can always validate that entry in the workflow and raise an exception if the workflow calculates a different value.
Badge +2

Solution identified after some discussion with a Nintex field support rep:

 

1. Define a field 'RunningScore' or similar and set initial value to 0.

 

2. For every individual score collected on the form, define a rule that tests the value of the selected score, and set 'RunningScore' to the value being tested. In other words
If [Score] = 1, then [RunningScore] value is 1. 

 

2. Repeat to find scores of '2 - the first one encountered will set the value of RunningScore to 2.

 

3. Repeat for score values 3 through n. 

 

It's not especially elegant but it works. 

Badge +2

An alternative solution has been identified - Kudos to Jake Dennison at Nintex UK, who took the time to think this up and test it. It's preferable to the preceding solution as it's simpler and scales better.  

The question fields remain (in my case) as a selection of 1, 2 or 3 from a drop-down, so each question has a 'score' value which is a single-line text field In the form

 

Create a text variable to combine the answers to all of the score fields as a string (for example, fields Score1, Score2, etc.:

Define varCombine as [Form.Score1]+[Form.Score2] and so on.

 

If all score fields are 1, for example, then varCombine will be "1 1 ..."

If Score1 is 2 and Score2 is 1, then varCombine will be "2 1 ..."

 

To test for the highest score, create a second variable that uses the following logic:

If varCombine contains 3 then 3, Else If varCombine contains 2 then 2, Else If varCombine contains 1 then 1, Else 0.

 

Define varResult as:

ifElse(contains([Form].[varCombine],"3"),"3",ifElse(contains([Form].[varCombine],"2"),"2",ifElse(contains([Form].[varCombine],"1"),"1","0"))).

 

The value of varResult can then be displayed on the form by assiging it to a label (to overcome the limitation that prevents a variable from being bound to a field). 

Reply