Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Formatting the JSON result for multiselect tokens control

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Formatting the JSON result for multiselect tokens control

    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.

    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%
    Which is almost right, but missing the 'data' array name. Here's the xbasic with sample JSON.


    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: 'bob@acme.com', display: 'Bob Smith' },
    '		{ value: 'fred@acme.com', display: 'Fred Jones' },
    '		{ value: 'louise@acme.com', display: 'Louise Teeger' },
    '		{ value: 'cecelia@acme.com', display: 'Cecelia Bouchard' },
    '		{ value: 'dan@acme.com', 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
    What do I have to add at the result level to get the data name?

  • #2
    Re: Formatting the JSON result for multiselect tokens control

    What Genie did you use to produce that setToken string? Why the + sign in front of setToken and why they use of :=. It looks very messy... and a bit dangerous.

    You are producing JSON from a SQL Statement, so, again, I'm not sure why you'd include static Genie output.

    The whole point is returning a string from XBasic. You've got a properly formatted JSON string in your json var. The JSON string is a list of object, all in an Array. All you need to do is add the bit that Alpha requires... a name for the Array... all inside an object. So... add it as a string. Alpha figures out the format on the client side.

    Your code will be...

    Code:
    dim json as c 
    json = rs.toJSON()
    json = "{data:" + json + "}"
    setToken = json
    If you debug through XBasic, you'll see that your json var now carries the same format as the XBasic example... and that it's all just a string passed back to the client.

    Comment

    Working...
    X