Xpath retrieve in Java Action

0
I am trying to do an xpath retrieve in a Java Action. The retrieve in Mendix is as follows: [AppointmentsManagement.Appointment_Customer = $Customer] [StartDateTime < '[%BeginOfCurrentDayUTC%]'] [AppointmentsManagement.Appointment_Account_Carers = $CareWorkerAccount] [AppointmentType = 'Care']   In the Java action, I wrote as follows: String NumberOfTimesXpath = String NumberOfTimesXpath = "//AppointmentsManagement.Appointment[AppointmentsManagement.Appointment_Customer/CustomerManagement.Customer/id = " + CustomerParameter1.getMendixObject().getId() + "]" + "//AppointmentsManagement.Appointment[StartDateTime < " + this.CurrentDateParameter1+ "]" + "//AppointmentsManagement.Appointment[AppointmentsManagement.Appointment_Account_Carers = " + carerAccount + "]" + "//AppointmentsManagement.Appointment[AppointmentType = 'Care']";   I keep getting an error as follows:   com.mendix.modules.microflowengine.MicroflowException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.connectionbus.ConnectionBusRuntimeException: An exception has occurred for the following request(s): InternalXPathTextGetRequest (depth = 0): //AppointmentsManagement.Appointment[AppointmentsManagement.Appointment_Customer/CustomerManagement.Customer/id = [MendixIdentifier:: id=10977524091715698 objectType=CustomerManagement.Customer entityID=39]]//AppointmentsManagement.Appointment[StartDateTime < Thu Mar 15 17:06:12 GMT 2018]//AppointmentsManagement.Appointment[AppointmentsManagement.Appointment_Account_Carers = usermanagement.proxies.Account@a2ff2701]//AppointmentsManagement.Appointment[AppointmentType = 'Care'] at CarePlanManagement.SUB_AccountWithMilesForAppointment_CareTeam (JavaAction : 'JA_GetCarerAccountsWithMiles') at CarePlanManagement.IVK_AccountWithMilesForAppointment (SubMicroflow : 'SUB_AccountWithMilesForAppointment_CareTeam') at AppointmentsManagement.IVK_OpenAddAccount_Appointment (SubMicroflow : 'IVK_AccountWithMilesForAppointment') Advanced stacktrace: at com.mendix.modules.microflowengine.MicroflowUtil.processException(MicroflowUtil.java:144)   I have no idea what I am doing wrong
asked
4 answers
5

Hi Kofi,
As a workaround why dont you do the retrieve in a microflow and then call that microflow from java. Its much simpler to write the XPath that way and you will also be alerted when some Entities or attribute names change. I find this much safer than doing the retrieve in java. IOP you should use java only for the things that you can not do in mendix.

-Andrej

 

answered
4

Agree with Andrej, but if you must do this in Java, you can also use the XPath generator class of the Community Commons module. See https://www.mendix.com/blog/easy-xpath-retrieval-in-java/

answered
3
  • Your not passing the id's correctly, do:

 

CustomerParameter1.getMendixObject().getId().toLong()
  • Your not passing the date correctly (I think a unix timestamp is expected there)
answered
0

Related, Core now also has createXPathQuery and retrieveXPathQueryEscaped which you can use instead of building the entire String

            var xpq=com.mendix.core.Core.createXPathQuery(
                "\
                //System.FileDocument[\
                   contains(Name,'$nam')\
                   and\
                   contains(Name,'$ext')\
                   and\
                   Size>$siz\
                ]\
                "
            );
            xpq.setVariable("nam","a")
            xpq.setVariable("ext","xls")
            xpq.setVariable("siz",100)
            xpq.setAmount(8)
            xpq.setOffset(0)
            xpq.setDepth(1)
            xpq.setDisableSecurity(true)
            xpq.addSort("Size",true);
            var arr_obj=xpq.execute(context);
            ...
        var xpathFormat="//System.FileDocument[\
                contains(Name,'%s')\
                and\
                contains(Name,'%s')\
                and\
                Size>%s\
            ]";
        var amount=1;
        var offset=0;
        var sort={};
        var depth=1;
        var arr_obj=com.mendix.core.Core.retrieveXPathQueryEscaped(
            context,
            xpathFormat,
            amount,
            offset,
            sort,
            depth,
            "xlsx",
            "a",
            "100"
        );

 

answered