I'm currently working with the lookupObj from the svyLookup module and I'm not sure what I'm doing wrong, but the onSelect function isn't letting me use the record param it's given. Whenever I application.ouput(record.contact_uuid) it returns <null>, but if I application.ouput(record) it returns the selected record. I've tried this twice now, with the current form I'm working on, and with the orderItemsTable in the cloud sample solution, both of which haven't worked in their specific ways.
Here is the current form im working on:
- Code: Select all
function onSelect(record, values, lookup) {
var contactFoundset = datasources.db.cpro.contacts.getFoundSet()
contactFoundset.find()
contactFoundset.contact_uuid = record.contact_uuid
var found = contactFoundset.search()
application.output(contactFoundset)
application.output(record)
if (found > 0) {
var currentContact = contactFoundset.getRecord(1);
if (record) {
var newOrder = currentContact.contacts_to_orders.createRecord()
if (!databaseManager.saveData(newOrder)) {
plugins.dialogs.showErrorDialog('Error', 'Failed to create a new order for the selected contact.');
return;
}
scopes.global.showForm(forms.orderEdit, newOrder);
}
}
}
Here is the orderItemsTable function:
- Code: Select all
function onSelect(record, values, lookup){
if (values && values.length) {
foundset.pricelist_fk = values[0];
}
if(record) {
record.forEach(function(rec){
if (foundset.selectRecord(foundset.pricelist_fk,rec.pricelist_uuid)) {
// increase quantity if product already in order
foundset.quantity = foundset.quantity + 1;
} else if(foundset.selectRecord(foundset.stock_fk,rec.stock_uuid)) {
// increase quantity if product already in order
foundset.quantity = foundset.quantity + 1;
} else {
// create a new order line for each product selected in lookup
var newRec = foundset.getRecord(foundset.newRecord())
newRec.quantity = 1;
newRec.make = rec.make;
newRec.model = rec.model;
newRec.price = rec.price;
newRec.serial_number = rec.serial_number
updateStock(0, 1, newRec)
}
})
}
orderTotal()
}
For the order items table, I basically copied over the code from the cloud sample solution, but it hasnt seemed to work with anything I try.
Also I was wondering whether you can make the lookupObj.setMultiSelect(false) but have the form searchable at the same time?
Thanks!
Alasdair