Skip to content

Instantly share code, notes, and snippets.

@weiserman
Created October 10, 2022 08:24
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 weiserman/97edeaaf08b9335c2076701a74685dd0 to your computer and use it in GitHub Desktop.
Save weiserman/97edeaaf08b9335c2076701a74685dd0 to your computer and use it in GitHub Desktop.
Frappe Client Script
frappe.ui.form.on('Library Member', {
refresh(frm) {
// Get the library memmbers first name from form JavaScript object
let first_name = frm.doc.first_name;
console.log(frm.doc);
// Check we have a name value and call the backend using an AJAX like call
// On completion call an Arrow function with results
// Backend function is written in python in the api.py file
if (first_name){
frappe.call({
method: "library_management.api.get_rental_articles",
args: {first_name: first_name}
}).done((r) => {
// Have a dictionary returned so let's initialise child table by setting it to an empty array
frm.doc.rental_transactions = []
// loop through response
$.each(r.message, function(_i, e){
let form_entry = frm.add_child("rental_transactions")
form_entry.transaction = e.name;
form_entry.article_name = e.article;
form_entry.type = e.type;
form_entry.date = e.date;
})
// Refresh the UI element so it shows
refresh_field("rental_transactions");
console.log(r)})
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment