Contains function not working

What is the problem? Please be detailed.
I'm trying to use the contains() function but always get this answer when deploying it
Unexpected KoBoCAT error 400: {"detail":"ODK Validate Errors:\norg.javarosa.core.log.WrappedException: Error evaluating field 'drug_combin2': The problem was located in calculate expression for ${drug_combin2}\nXPath evaluation: cannot handle function 'contains' =>

What ODK tool and version are you using? And on what device and operating system version?
Xls from on excel and Kobo tool box

What steps can we take to reproduce the problem?

Create a calculate field with the contains() function and try to deploy it

What you have you tried to fix the problem?
change the way of how te function is working, but dind't find anything

Anything else we should know or have? If you have a test form or screenshots or logs, attach here.

Can you please post the actual calcuation that you are attempting. contains() is a base XPath 1.0 string function, so I'd be a little surprised if its unsupported. Certainly KoboToolbox does support contains()

Thanks for your support.
I tried in quite different ways to follow the patterns mentionned in the documentation "contains(string, substring)", but found few practical examples, so I made perhaps a mistake.
My latest attempt was something like contains(${drug_choice_concact},'amoxi').
Thansk again for your support.

Your attempt looks valid. The following XSLForm with it works as expected under KoboToolbox, perhaps verify for yourself:

test.xls (5.5 KB)

If it doesn't work under KoboCat then its a bug/limitation in KoboCat, and all I can say is perhaps open an issue about it it their github project.

Thanks again for your support and confirmed my assumption.
It seems indeed coming from KoboCat as I tried to deploy your form in two different instance (the official one online and one installed on a local server) and both failed with the same message "XPath evaluation: cannot handle function 'contains'.
Will report to them

BTW, depending on how your ${drug_choice_concact} is constructed (eg is it from a multi-select?) you might also try using selected() instead of contains(). Whereas contains() will match any substring, selected() will (only) match whole words in a space separated string [which is how the results of a multi-select question are actually stored].

Yep. Thanks ! I already think to this one...Really thanks again for your support !

Sorry for reviving an old thread but in case someone else finds it I wanted to confirm the issue has been resolved. A calculate with contains() works when deploying to kobocat. I think this was an issue last year because KoBo was using a fork of pyxform at the time (it now uses the source repo again).

[@edmond I just came across this thread. I suggest posting these issues on the KoBo community forum going forward.]

2 Likes

Hi @Tino_Kreutzer,

I posted it on the KOBO Forum : https://community.kobotoolbox.org/t/contains-function-not-working/4232.
I tried and the issue was fixed :slight_smile:

All the best,
Chloé