Last active
April 11, 2019 21:45
-
-
Save stevewithington/af2aafa7aae867d7c1a610a0ba1b8f0e to your computer and use it in GitHub Desktop.
Mura Populate Form Select Menu With Custom User Subtype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Select `Custom Object` as `Source` | |
// Then, the other `Source` is the path to the cfc file under the site. | |
component extends='mura.cfobject' { | |
// On the form, select 'Custom Object' then for the 'Source' enter the dotted notation path to wherever you placed this file. | |
// For example 'includes.myCustomValues' if your file was called 'myCustomValues.cfc' and placed under the 'includes' directory. | |
// Mura will automatically invoke the getData() method below | |
// See http://www.getmura.com/blog/populating-form-builder-dropdowns-via-remote-objects/ for more information | |
private any function getRS() { | |
var m = application.mura.getBean('m').init(session.siteid); | |
var employees = m.getFeed('user').where().prop('subtype').isEq('Employee'); | |
var rs = employees.getQuery(); | |
return rs; | |
} | |
public any function getData() { | |
var hash = ''; | |
var row = ''; | |
var dataRecordOrder = []; // array of keys in the desired order | |
var dataRecords = {}; // struct of structs | |
var dataSet = {}; // the return value | |
// your rs must have an IDCol, ValueCol, LabelCol | |
var rs = getRS(); // this is YOUR query! from YOUR DB! | |
// Query Example : how to add records from a database as options | |
for ( row in rs ) { | |
hash = Hash(row.userID); | |
ArrayAppend(dataRecordOrder, hash); | |
dataRecords[hash]['dataRecordID'] = hash; | |
dataRecords[hash]['label'] = row.Fname & ' ' & row.Lname; | |
dataRecords[hash]['value'] = row.userID; | |
} | |
// build the final dataSet | |
dataSet.dataRecordOrder = dataRecordOrder; | |
dataSet.dataRecords = dataRecords; | |
//WriteDump(var=dataset, abort=1); | |
// return the dataSet | |
return dataSet; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment