Skip to content

Instantly share code, notes, and snippets.

@rmehta
Last active December 16, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmehta/5452216 to your computer and use it in GitHub Desktop.
Save rmehta/5452216 to your computer and use it in GitHub Desktop.
cur_frm.cscript.item_prefix = function() {
// will be called on change of item_prefix
// note: it is important to specifiy tablename.fieldname
// in query as permissions are evaluated on this basis
// and sql keywords must be in CAPS
wn.call({
method: "webnotes.widgets.query_builder.runquery",
args: {
"query":"SELECT `tabItem`.name \
FROM `tabItem` WHERE `tabItem`.name like '" + doc.item_prefix +"%' \
ORDER BY name desc limit 1"
},
callback: function(r) {
// returned last value
last_id = r.values[0][0]
var new_id = /* some id logic */
cur_frm.set_value("item_code", new_id);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment