How to select last element of a business object

1
0
-1

hi;

I create a form with UI designer version 7.11.1.

I move the object in the form, it creates automatically a table and two variables: mSA of business data type and mSA_selected of string type.

I want to display the last record of the variable mSA, i try to add a filter in mSA variable like this:

select * from mSA order by persistenceId DESC LIMIT 1

but it displays the first one. the same result if i emplace DESC by ASC. ?

1 answer

1
0
-1

Hi,

i try to add a filter in mSA variable

I don't understand what you are trying to do here. You have two choices:

  • Create a custom query in the BDM that uses SELECT m FROM mSA m ORDER BY m.persistenceId DESC
  • Sort the result of the query client side using javascript and reverse the array

In addition you can't use LIMIT on your queries, because Bonita already configure a pagination mechanism for multiple result queries.
So you can use p=0 and c=1 query parameters to only return the first element of the result.

HTH
Romain

Comments

Submitted by maouachria on Thu, 08/27/2020 - 12:04

thanks sir what you mean by m in the query? is it a variable ?

Submitted by maouachria on Thu, 08/27/2020 - 14:26

1- the same result with the query proposed:

SELECT m FROM mSA m ORDER BY m.persistenceId DESC.

even I used : SELECT m FROM mSA m ORDER BY m.persistenceId ASC.

view?usp=sharinghttps://drive.google.com/file/d/1sIOQ-wbp5shCtDUJRZi1oaDGzHyafuXI/view?usp=sharing

2- I don't understand the second solution!!!

Submitted by romain.bioteau on Thu, 08/27/2020 - 17:47

This is not where custom queries are defined.

You need to go in the Studio BDM, select the mSA object (by the way Business objects should always start with a capital letter) and go to queries, select custom and create the query here (see documentation for more information. Then redeploy the BDM and it will be visible in the UID UI.

The place you are using to write the query in your image is a search filter for the list of available queries in the table below.

The second solution consist in using the default find query on your Object to populate a UID variable (myElements) and then transform this result using another variable myLatestElements of type javascript that does something like:

return $data.myElements.slice().reverse();

HTH
Romain

Submitted by maouachria on Mon, 08/31/2020 - 12:41
Submitted by maouachria on Mon, 08/31/2020 - 18:50

how I can use this solution i dont understand :

The second solution consist in using the default find query on your Object to populate a UID variable (myElements) and then transform this result using another variable myLatestElements of type javascript that does something like:

return $data.myElements.slice().reverse();

this is a part of bos:

query

Submitted by maouachria on Mon, 08/31/2020 - 18:50

I added in UI designer two variables:

mSA

myLastest Elements

I added also myLastest Elements as Content like this:

content

but it just reverse the elements and displays them all.??????????????

Submitted by romain.bioteau on Thu, 09/03/2020 - 13:57

You can select element in JS array using this syntax:
myLastestElements[0] where 0 is the element index of the first element in the array or use shift() function.

Or directly call shot() function in your javascript expression like this :
return $data.myElements.slice().reverse().shift()

Submitted by maouachria on Thu, 09/03/2020 - 16:23

:( it does not work

Notifications