Request: XML code to grab the ID of a specific case sharing group

Hello folks -- Huge thanks to anyone that can give me a hand in determining
what XML code would do the following, for the part of my app that handles
walk-ins to a clinic. William and Sheel have both really helped me
understand this, so I am almost there.

When I register a walk-in to a certain clinic, I am not able to use case
sharing, so my job is creating code in one of my forms to do the following.

When a new case is being created by one specific "walk-in" form, the form
can't assign that case to a group, because the user is in multiple groups.
But I ultimately need the form to assign that case to a special case
sharing group I have made that will include just two clinics.

I currently have the app functioning using that method described in the
help document called "Assigning cases to one of multiple groups." But it's
kind of embarrassing to ask the user "OK, in this question, please choose
the group below that is called "XXX." I really hope I can automate it. I
think it will not be too hard for someone that is good at this.

Having looked at what I need, I think that the form simply needs some code
inside it, slightly similar to the four lines of code that are provided in
that "assigning cases" help document.

The code would automatically:

  • (1) First, it would look at the contents of a field called "site" that
    is actually present in that user's own user account (you know how users can
    have an extra optional field added to them. We will have this "site" user
    field populated for all users. For example, for a given user, it might
    find that that "site" field had a contents of "30.") Then,
  • (2) the code would determine the ID of the existing case sharing
    group that had that exact same name (i.e. it would find the existing case
    sharing group I had made called "30.") And it would place* that group's
    ID *into a hidden value (or a question) in that form.
  • (3) I believe that is all I need... because then I would simply pass
    that ID as the "owner_ID" of both the current form and also a
    child-case that is created by this form over in the case management
    settings. And those forms would live on, owned by the correct group!

I'm afraid I realistically won't be able to write the code myself.

If any of you can recommend what code would do this, it would definitely
make my week!

Eric

Hey Eric,

Assuming you're using custom user data for the site, I think you want a
hidden value with a calculate expression that is:

instance('groups')/groups/group[name=instance('commcaresession')/session/user/data/site]/@id

And set that to owner_id case property.

You will also need to include the group instance () as described on that page.

Note that this will crash on your users if you haven't properly setup the
groups and custom user data, so I'd be very careful rolling it out.

ยทยทยท On Mon, Jun 29, 2015 at 12:05 PM, Eric Stephan wrote:

Hello folks -- Huge thanks to anyone that can give me a hand in
determining what XML code would do the following, for the part of my app
that handles walk-ins to a clinic. William and Sheel have both really
helped me understand this, so I am almost there.

When I register a walk-in to a certain clinic, I am not able to use case
sharing, so my job is creating code in one of my forms to do the following.

When a new case is being created by one specific "walk-in" form, the form
can't assign that case to a group, because the user is in multiple groups.
But I ultimately need the form to assign that case to a special case
sharing group I have made that will include just two clinics.

I currently have the app functioning using that method described in the
help document called "Assigning cases to one of multiple groups." But it's
kind of embarrassing to ask the user "OK, in this question, please choose
the group below that is called "XXX." I really hope I can automate it. I
think it will not be too hard for someone that is good at this.

Having looked at what I need, I think that the form simply needs some code
inside it, slightly similar to the four lines of code that are provided in
that "assigning cases" help document.

The code would automatically:

  • (1) First, it would look at the contents of a field called "site"
    that is actually present in that user's own user account (you know how
    users can have an extra optional field added to them. We will have this
    "site" user field populated for all users. For example, for a given user,
    it might find that that "site" field had a contents of "30.") Then,
  • (2) the code would determine the ID of the existing case sharing
    group that had that exact same name (i.e. it would find the existing case
    sharing group I had made called "30.") And it would place* that
    group's ID *into a hidden value (or a question) in that form.
  • (3) I believe that is all I need... because then I would simply pass
    that ID as the "owner_ID" of both the current form and also a
    child-case that is created by this form over in the case management
    settings. And those forms would live on, owned by the correct group!

I'm afraid I realistically won't be able to write the code myself.

If any of you can recommend what code would do this, it would definitely
make my week!

Eric

--
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-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Great -- I'm so happy to get working on this fix! thank you!

I'm going to give this a try. and the one confusion that I had about what
you did above, I realize I'm not confused about after all. I can't pretend
I would have come close to drafting that code myself, but I can... imagine
somehow that it looks like it makes sense. :slight_smile: Thanks and I will let you
know if it works

Eric

For your info, the code that you gave me worked perfectly. Now the app
automatically adds the user to the correct group without any trouble on the
part of the user. I really appreciate your help, and the help from the rest
of the folks. Thanks!