I have a MultiselectTokens control that I'm trying to use an Xbasic to populate the choices. However, I can't get the JSON result formatted correctly. The genie produces this.
Which is almost right, but missing the 'data' array name. Here's the xbasic with sample JSON.
What do I have to add at the result level to get the data name?
Code:
+setToken := <<%str% [ {"value" : "1000", "display" : "XXS"}, {"value" : "1001", "display" : "XS"}, {"value" : "1002", "display" : "SM"}, {"value" : "1003", "display" : "MED"}, {"value" : "1004", "display" : "LG"}, {"value" : "1005", "display" : "XL"}, {"value" : "1006", "display" : "XXL"}, {"value" : "1007", "display" : "0X"}, {"value" : "1008", "display" : "1X"}, {"value" : "1009", "display" : "2X"}, {"value" : "1010", "display" : "3X"}, {"value" : "1011", "display" : "4X"}, {"value" : "1012", "display" : "5X"}, {"value" : "1013", "display" : "00"}, {"value" : "1014", "display" : "0"}, {"value" : "1015", "display" : "2"}, {"value" : "1016", "display" : "4"}, {"value" : "1017", "display" : "6"}, {"value" : "1018", "display" : "8"}, {"value" : "1019", "display" : "10"}, {"value" : "1020", "display" : "12"}, {"value" : "1021", "display" : "14"}, {"value" : "1022", "display" : "16"}, {"value" : "1023", "display" : "18"}, {"value" : "1024", "display" : "20"}, {"value" : "1025", "display" : "22"}, {"value" : "1026", "display" : "24"}, {"value" : "1027", "display" : "26"}, {"value" : "1028", "display" : "28"}, {"value" : "1029", "display" : "30"}, {"value" : "1030", "display" : "32"}, {"value" : "1031", "display" : "One Size"} ] %str%
Code:
function setToken as c (e as p) 'Generates the choices for a multi-select token control. 'The e object that is passed in includes: 'e.tmpl = UX definition 'e.arguments - argument values 'Your code must return a JSON object that defines the control choices. 'Example: 'setToken = <<%str% '{ ' data: [ ' { value: '[email protected]', display: 'Bob Smith' }, ' { value: '[email protected]', display: 'Fred Jones' }, ' { value: '[email protected]', display: 'Louise Teeger' }, ' { value: '[email protected]', display: 'Cecelia Bouchard' }, ' { value: '[email protected]', display: 'Dan Bachman', listDisplay: 'Dan Bachman (C.E.O.)' } ' ] '} '%str% 'Notice that the data array has a list of objects. Each object must have a 'value' and a 'display' property. The 'listDisplay' property is optional. 'The 'value' property is used for the control value, the 'display' property is used in the token display and the 'listDisplay' 'property is used in the drop-down list that displays the control's choices. 'DIM a SQL arguments object debug(1) dim args as sql::arguments 'DIM an Xbasic AlphaDAO connection object dim cn as sql::connection dim flag as l ''open the connection object to connect to the Database flag = cn.open("::Name::SQL") dim sql as c sql = "SELECT SizeID as value, Size as display FROM Web_Sizes" 'turn portable SQL on. (for more information on portable sql search in help (https://www.alphasoftware.com/documentation) 'execute the SQL - pass in the sql::arguments object flag = cn.execute(sql,args) if flag = .f. then 'an error occurred - get the error message from cn.callresult.text 'report the error, close the database and then end the script dim errortext as c errortext = cn.callresult.text cn.close() end if 'DIM a SQL::Resultset object dim rs as sql::resultset rs = cn.resultset 'get the JSON from the query dim json as c json = rs.toJSON() setToken = json 'Clean up by freeing the resultset and then closing the database cn.freeresult() cn.close() end function
Comment