Case update in handwritten Xform

115 views
Skip to first unread message

yashseth

unread,
Aug 26, 2013, 7:50:16 AM8/26/13
to commcar...@googlegroups.com, Nandini Bhardwaj
Hi guys, 
We are using handwritten Xforms in our application ( not made through form designer). We need to update a few cases based on data recorded during the filling of the form on the mobile device. 
Eg: A group of people see a video, so this video should be added to the list of videos that they have seen.
  • How can this be done ? 
  • Is there a way to ensure that this only happens once the form is submitted ? 

Clayton Sims

unread,
Aug 26, 2013, 1:25:39 PM8/26/13
to commcare-users, Nandini Bhardwaj
Yashseth,

Just so we're on the same page, your goal is to record a field in (1 -> N) different cases in the same form?

-Clayton


--
You received this message because you are subscribed to the Google Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commcare-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Yash Seth

unread,
Aug 26, 2013, 1:32:06 PM8/26/13
to commcar...@googlegroups.com, Nandini Bhardwaj

Yes that's right.  But the primary goal being to update the value of an attribute of a case.  The cases to be updated will be filtered on one of their attributes .

You received this message because you are subscribed to a topic in the Google Groups "commcare-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/commcare-users/rxvCL0X7uBI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to commcare-user...@googlegroups.com.

Clayton Sims

unread,
Aug 26, 2013, 2:06:17 PM8/26/13
to commcare-users, Nandini Bhardwaj
Gotcha,

So you want to display a list of the cases that match some filter, and then select _which_ of those cases will have their property updated?

-Clayton

Yash Seth

unread,
Aug 26, 2013, 2:07:52 PM8/26/13
to commcar...@googlegroups.com, Nandini Bhardwaj

That's right. 

Clayton Sims

unread,
Aug 28, 2013, 2:48:57 PM8/28/13
to commcare-users, Nandini Bhardwaj
So you can do this with CommCare by inserting some variables and calculations to build a repeat which indexes into the multiselect results. This would look something like:

<!-- ... -->
<!--  In the instance -->
<num_children/> <!-- total number of selected elements -->
<cur_children/> <!-- an counter for each element as the models are created -->
 
<!-- Repeat Host -->
<child_info index="" id="">
<!-- Repeat question models go here -->
</child_info/>
 
<!--... and then for the binds ...-->
<!-- Count the total number of values to iterate over -->
<bind nodeset="/data/num_children" type="int" calculate="count-selected(/data/multiselect_answer)"/>
 
<!-- count the number of repeats that _currently_ exist. -->
<bind nodeset="/data/cur_children" type="int" calculate="count(/data/child_info)"/>
 
<!-- When a new repeat is created (jr-insert fires), capture its index -->
<setvalue event="jr-insert" ref="/data/child_info/@index" value="int(/data/cur_children) - 1"/>
             
<!-- capture the ID (in this case the case_id) of the thing we're iterating over -->
<bind nodeset="/data/child_info/@id" calculate="selected-at(/data/multiselect_answer,../@index)"/>
 
<!-- ... finally the repeat itself -->
<repeat nodeset="/data/child_info" jr:count="/data/num_children">
<!-- This is optional, but will suppress the confusing "1/1, 2/2 progression" and display only the repeat header's name. -->
<jr:entryHeader><output value="$name"/></jr:entryHeader> 
<!-- Repeat questions go here -->
</repeat>

If you inserted a <case> update block into the repeat, it will be able to create all of the relevant cases. You shouldn't need any actual questions in the repeat block itself, only hte updates.

-Clayton
Reply all
Reply to author
Forward
0 new messages