I have two calculations and triggers for category_1 and category_1.1. Each works fine when used separately, but when I try to merge them, they stop functioning correctly. I’ve attached both logic files in XLS format separately. Could you help me merge them so they work together? I’d really appreciate your assistance!
I’ve been asking you all for so many times and have tried multiple hit-and-trial methods to find a solution. D Logic_1.xlsx (19.3 KB) Logic_2.xlsx (19.3 KB)
espite my efforts, I still need help resolving it. Please assist me in fixing this issue.
I looked at your 2 forms but its still not entirely clear to me what you are trying to do with the category_1 and category_1.1 questions… Could you perhaps try to explain in words what you are trying to accomplish with these?
FWIW, a (single) trigger basically says perform such-n-such calculation whenever this identified trigger question is explicitly modified by the user. More precisely, upon the identified xforms-value-changed event, explicitly perform the stated setvalue action [which is all nicely hidden in XLSForm, with a trigger column identifying the responsible question that will ‘trigger’ the event, and the associated calculation column providing the actual calculated value to store in the identified row].
So in that sense, you cannot directly use a single trigger to, say, perform such-n-such calculation when (either) category_1 or category_1.1 change; that actually requires two explicit triggers (!)
Again, if you can perhaps explain what you are trying to accomplish with these triggers, it may be possible to determine the best approach.
What i try wanna do was basically to automatically select options on the based of 1st and last question.
1.1 Proceed with the interview
1.2 Partial
1.3 Refused
1.4 Not Eligible
And this category question is above 1st question.
When 1st question is selected, it should automatically click on 1.2 Partial option and when last question is selected it should automatically click on 1.1 Completed option.
And issue was I was able to do only one logic either on 1st or last question only. I figured out, it was due to two logic and triggers on same question. And after so many hit and trail, I split options in two questions and put both logic seperatly and hide second question and it works.
But issue was both questions should work as single options.
so, logic_1 has the solutions to this above picture.
and logic_2 has the solutions of automatically selecting options based on 1st and last questions.
But due to multiple logic on same option 1.1 Completed and 1.2 Partial, I think I am not able to use logic_1 and logic_2 at once.
So basically I wanna merge it.
Kindly how can i resolve this issue.
I hope you get to my point.
I just want to handle Multiple Triggers in one calculation field in kobotoolbox.
I tried to do it by using calculation field as well for each trigger
but that doesnt work as well.
Short answer is you cannot have more than one question trigger a calculation in XLSForm. To accomplish this, you basically have to have two separate calculations, each with one of the triggers, and then somehow combine the results of the two calculations appropriately.
As an example, the following form has two temperature inputs - one if degC and the other on degF - and I want any change to either of them to ‘trigger’ a calculation to record when the temperature was last changed by either of them.
Ideally, I’d just like to have a single temp_ts calculation that is triggered by any change to tempC or tempF. But, alas, you can only have a single entry in the trigger column. So instead I have two calculations, one for each (tempC_ts and tempF_ts), and then combine their results in a 3rd temp_ts calculation. The resulting behavior is that whenever I change either, the calculated temp_ts reflects the latest change which is what I want (obviously, this combiner calculation will depend of your specific usecase).
Have a play and see if you can come up with something similar to suit your need.
[Aside: long answer, you can actually have two different XForm controls (the ‘triggers’) with basically the same xforms-value-changed event performing the same set-value action with the same calculation and storing their result to the same XML instance element. However, this level of customization is not exposed via the XLSForm spec, and is only available in raw XML XForms. So in Kobo XLSForm you have to perform these additional acrobatics].
Thank you so much. It works after using two calculation and used two triggers respectively. But it only works after removing all the relevant and required or any other fields.
I used trigger in first and last question and after emptying all other relevant and required field, then only it works. But my question must need relevant and required field.
Yes, each trigger has to have its own separate calculation (or, equivalently, each triggered calculation has to have its own separate trigger). You may then need to combine/consolidate these 2 results in an appropriate manner if you want to turn them into a single result field.
only works after removing all the relevant and required or any other fields.
Without understanding your precise logic I cant really say what to do. But suffice to say, the behavior of these (now) 2 triggers is ostensibly independent of any additional relevant/required logic. A trigger basically says: “Whenever the user changes the response to Question A, run this calculation and store the result in Question B”. So whatever additional form logic you might have needs to keep that in mind; eg if Question A becomes non-relevant, it wont ever get shown, so the user cant ever change it, so it wont ever be able to trigger anything.
I have put triggers in Q1 and Q2 and based on that category_1 will react.
Now what I tried to do is , I wanna show Q1 question if 1.2 or 1.2 is selected in category_1 and was not able to do so.
First, looking at your form and trying to understand the intent, I dont think there is any reason to be over-complicating it with triggers in the first place (yet alone trying to merge multiple triggers!). Rather, it seems you can accomplish what you desire with basic relevant expressions, and no additional calculations:
First Question is only shown (ie relevant=true) if the user selects ‘Proceed’ or ‘Partial’ for the category_1 question. Then Last Question is only shown after they respond to First Question.
It’s still probably worth pointing out the other errors. First, you shouldn’t have a calculation directly on a select question; doing so basically means it doesn’t matter what the user selects, its immediately going to be clobbered by the calculation result (all calculations are continuously re-evaluated any time you answer any question in the form!). Next, relv() does nothing; there are no XPath functions called ‘relv’! (and this is not how you reference your relv calculation in your form; that would be ${relv} instead). Finally, for the last 2 calculations, you have calculation=Q1() and calculation=Q2(). Presumably you were intending to reference the Q1 and Q2 questions in your form; again, the correct way to reference other results in a form is via ${some_name}; or in this case ${Q1} or ${Q2}.
I might suggest working thru some XLSForm tutorials to make sure you understand these fundamental concepts. eg All Products - KoboToolbox Academy. Or there are a variety of other online resources for how to write XLSForms that are easily found via googling.