Automatic Next Serial number assigned to new registered case

We need automatic next serial number should be assigned to each new case. Like I am xyz Mobile worker and till now i registered 10 cases for the 11 the case it should have come the automatic 11th number and it go on 12, 13, 14 …100 … as per new registration. Please suggest any suggestion or magic of any logic it will help us lot.

Thank you.

Hi Sagar,

What you are describing sounds like a common implementation of the User Case Feature, which will allow you to retain a running counter for each mobile user which is incremented after each case registered.

-Clayton

Hi there, thanks for this reply, that’s very helpful.

Is there any way to increment serial numbers across case registrations regardless of which mobile user registered the case?

One way to do this might be to somehow retrieve the size of the whole registration table and add one to that, but I don’t know if there is a way to do that?

Hi Clayton,

Thank You very much.

Hi,

Unfortunately this workflow is quite difficult to implement due to the difficulty of keeping multiple offline systems capable of continuing to create unique numbers.

The way most projects address this challenge is to issue each CommCare user a unique individual ID, and then to append this incrementing serial ID into a format, so one user would generate the ID

2-1432

and another might generate

4-1432

-Clayton

Thanks for your reply.

I tried to setting up a serial counter in the registration form using the calculate condition:

coalesce(#user/reg_id,0) + 1

However, it seems coalesce doesn’t work in this case. If I test coalesce with an empty hidden value generated from a form variable, it works fine, but as soon as I use #user/reg_id then the whole expression generates null instead of 1.

Within the form settings, we have already indicated that #user/reg_id should be saved as a user property and a case property. It doesn’t change, if we only save it as a user property, and not a case property.

Hi,

It seems like coalesce might be doing something unhelpful here, can you try swapping over to a more manual check, IE:

if(#user/reg_id = ‘’, 0, #user/reg_id) + 1

and see if that works?

-Clayton

Doesn’t work with the manual logic.

Again if I use a form variable that is hidden it works fine.

See attached screenshot.

Also does not work if I test it on an actual phone instead of the emulator.

I was wondering, if anyone had any new ideas about this?

The only thing that I can think if is that reg_id actually has a value set that is resulting in confusing behavior. I just reproduced the example in a small test form and it is behaving as expected.

If you display the value of reg_id from the usercase directly, is there some chance it’s actually currently set to “-1”?

Hi Clayton,

Thanks for taking time to help out with this! I tried displaying a few user values that were externally set like username and phone_number and those worked fine. Then I tried creating a custom user property to set the value of reg_id directly to see if it would display and that also worked fine. Then I went back to the original set-up and tested the counter and now it works! I don’t know exactly what changed, but at least it works now, so we are all set.

Thanks for all your help!