Hello Duarte, I wonder if this is down to differences in JS vs. config script in how truthiness is evaluated in `if` statements.
In JavaScript, if(...) evaluates to true if the returned value is a non-zero number (positive or negative). In Kamailio config script[1], in contrast, a value less than 0 is false, while only a positive value > 0 is evaluated as true. I'm not sure offhand what t_exists() actually returns. According to the documentation, it is a boolean, but it may be that the boolean isn't being propagated properly in the KEMI environment and is being turned into a negative value, which still evaluates as true, in JS. -- Alex > On Jul 17, 2024, at 1:37 PM, Duarte Rocha via sr-users > <[email protected]> wrote: > > Hello all, > > I'm using Kamailio with native script and KEMI in Javascript. > > I noticed that functions from the TM module can have different results if I > call them on KEMI or Native script. Is this intended behaviour? Don't they > share the state? > > In order to test this i made the following code : > > KEMI Code : > function ksr_request_route() { > try{ > if ( KSR.is_method("BYE") ) { > > print.error("BYE Request KEMI BYE") > > KSR.route("exists_test") > > if(KSR.tm.t_exists()) { > print.error("KEMI : Transaction exists") > } > else { > print.error("KEMI : Transaction does not exist") > } > > > > Native Code : > route[exists_test] { > > if( t_exists()) { > xerr("Native Script : Transaction exists \n"); > } > else { > xerr("Native Script : Transaction does not exist \n"); > } > } > > > I've also tried to change function call order but every time I get > "Transaction does not exist" on native and "Transaction Exists" on KEMI. > > Is this intended behaviour? Should I only call tm functions in native or Kemi > in order to have consistency ? > > Thanks in advance, > > Best Regards, > __________________________________________________________ > Kamailio - Users Mailing List - Non Commercial Discussions > To unsubscribe send an email to [email protected] > Important: keep the mailing list in the recipients, do not reply only to the > sender! > Edit mailing list options or unsubscribe: [1] https://www.kamailio.org/wikidocs/tutorials/faq/main/#how-is-the-function-return-code-evaluated -- Alex Balashov Principal Consultant Evariste Systems LLC Web: https://evaristesys.com Tel: +1-706-510-6800 __________________________________________________________ Kamailio - Users Mailing List - Non Commercial Discussions To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe:
