• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Putting specific keys into the text of a option menu
#1
Hi Guys

I'm stuck on something. I want to store a list of options in the livecloud database that i will insert into the text of an option menu , or combo Box Menu control (Basically a dynamic drop down list)

It works fine if there id only one record in the table, for example:

Code:
put cdb_read("companySetup","*","local") into tBranchData

//there is only one record in the companySetup table

set the text of button "branchTaxAppliedTo" of me to tBranchData[the keys of tBranchData]["brnCode"] && "-" && tBranchData[the keys of tBranchData]["companyName"]

// this works provided that there is only one record in the table

--I tried to convert the array with return (as per documentation, I also tried return and tab) on the next piece of code that has more than 1 record

put cdb_read("taxTypes","*","local") into tTaxTypes

put tTaxTypes[the keys of tTaxTypes]["taxTypes"] into tTaxTypes2 // there is only one row called taxTypes in the table

combine tTaxTypes2 using return and tab

set the text of button "taxType" of me to tTaxTypes2


I added the combine command in the hope that it will work, but it didnt
  Reply
#2
Hi sid,

The keys of the output array are recordIDs of the records. When you say "the keys of tBranchData", there is only one record in the table so there is only one recordID in the keys of tBranchData. Because of this, tBranchData[the keys of tBranchData] evaluates correctly. However, when you say "the keys of tTaxTypes", there are multiple records in the table so there will be multiple keys in tTaxTypes. Because of this, tTaxTypes[the keys of tTaxTypes] will not evaluate correctly.

The following is one way of creating the list you want:

Code:
repeat for each key xRecordID in tTaxTypes
  put tTaxTypes[xRecordID]["taxTypes"] & lf after tTaxTypesList
end repeat
delete char -1 of tTaxTypesList

set the text of button "taxType" of me to tTaxTypesList
  Reply
#3
Thanks Efrain

This worked like a bomb. 

I have a feature request .

why don't you add a ,format parameter to the query command. This way us newbies will find it easy to code.

so, : put cdb_read("taxTypes","*","local")

can be: put cdb_read("taxTypes","*","local","tablist")

you can add 'datagrid list" etc


I must say, having no previous programming experience , I am 20 percent done writing an ERP product using livecloud and livecode. Im a big fan.

Thanks for the awesome response times and great customer service

Sid
  Reply
#4
function cdb_Query(pKey, pOperator, pValue, pTable, pTarget, pResultFormat)

We could add "datagrid" to pResultFormat.
Other format options could be added.
- JSON
- List from a single key
  Reply
#5
I just realized that you are not using a query to get your data in this example. I read it too fast. Sorry about that.

You can use function cdb_list(pTable, pTarget, pKeys)
https://docs.livecloud.io/List/
  Reply
#6
You may wonder what the difference is between cdb_list() and cdb_readKeys()

cdb_list() returns a line delimited string. If there are more than one key, the data is comma delimited by keys and line delimited by records returned. Choose this API if you do not need to the the recordIDs of the returned data. This API is perfect for Sid's needs above.

cdb_readKeys() returns a structured array with a primary key of recordID/keys/values. Choose this API if you need to know how to identify the results with recordIDs. This would not be a good fit for Sid's example as he would have to parse the data himself as in Efrain's sample code.
  Reply
#7
Thanks Mark and Efrain

This clarifies a lot

Sid
  Reply
#8
(02-12-2020, 06:53 PM)mark_talluto Wrote: function cdb_Query(pKey, pOperator, pValue, pTable, pTarget, pResultFormat)

We could add "datagrid" to pResultFormat.
Other format options could be added.
- JSON
- List from a single key

Hi Mark

is the pResultFormat parameter operational?

I can't seem to get it to work and still have to use the repeat code 

Sid
  Reply
#9
Hi Sid. I will have a look tomorrow morning. I'll let you know what I find out. If there is a bug, we can get that fixed quickly.
  Reply
#10
Hi Sid,

The current supported pResultFormat from cdb_query is "recordList" and "recordData".

"recordList" might not be useful for your use case since it just returns a list of cdbRecordIDs.

If you choose "recordData", you will still have to use the repeat code that Efrain provided from previous post.

Alternatively, you could use cdb_list suggested by Mark to avoid using the repeat code.
  Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)