Valuelists based on data

Hello,

I have a question concerning valuelists in Servoy Mobile.

I understand that “only custom valuelists are supported” in the Mobile side.

But in our case, we need absolutely to provide these valuelists by data from db.

Is there a way to make it from the Service side ?

For example : I have a table “Opportunity_status” which contains the possible values of my valuelist “Status”. I would like to retrieve the data of this table and push in an array (or in an object), to be able to retrieve my data in the Mobile side.

Thank you very much.

Yes this is possible.
You can add a extra foundset to the retval and use this to fill your valuelist.

So you add for example this to the ws_read:

var fs_codes = databaseManager.getFoundSet('db:/mobile/codes')	
	fs_codes.loadAllRecords()
	retval.addFoundSet(fs_codes, [])

Thank you very much for your answer ! I will try this soon and I will let you know

I successfully get offline valuelist data adding foundset to offline_data ws_read method

I couldn’t find sample code to manage mobile valuelist

Could you please provide me sample

thanks

Here a sample:

	var ids = []
	var values = []
	//set valuelists
	/** @type {JSFoundSet<db:/source/table>} */
	var fs = databaseManager.getFoundSet('db:/source/table')
	//remove this line if it gives a warning, in older version of servoy it is not needed in the last it is.
       fs.loadAllRecords()
	
	for (var i = 1; i <= fs.getSize(); i++) {
		var rec = fs.getRecord(i)
		 ids.push(rec.id)
		 values.push(rec.description)
	}
	
	appl

Thank you !

Hi, i revive this topic because i’m having trouble with a valuelist.

In the service solution I do:

var clientes_vl = databaseManager.getFoundSet('db:/contador_hs/clientes')
	retval.addFoundSet(clientes_vl, []);

retval has other foundset that works fine

and in the solutionOpen of the mobile solution i do:

	var ids = []
	var values = []
   
	/** @type {JSFoundSet<db:/contador_hs/clientes>} */
	var fs = databaseManager.getFoundSet('db:/contador_hs/clientes')
	fs.loadAllRecords()
   
	for (var i = 1; i <= fs.getSize(); i++) {
		var rec = fs.getRecord(i)
		ids.push(rec.cliente_id)
		values.push(rec.razon_social)
	}
	application.setValueListItems('clientes',values,ids)

am i missing something? When running the solution, the valuelist shows no records

Thanks in advanced,

Andres

add clientes_vl.loadrecords() to your service solution to make sure there is data in the foundset.

thanks, jos! that did it