Concatenating Fields into a New Field
Guide
Some important notes:
This was done // on saving / before_save, pull city and state values from address based on standard address shipping name and populate city_and_state field (both are custom fields)
console.log is (obviously) just for checking, but always good practice
r is a collection variable in JSON (?) format that needs to be parsed to its message and fields (which was also pulled during frappe.call)
frappe.client.get_value is for client side scripting, while frappe.db.get_value is for server side scriptingSome important notes:
This was done // on saving / before_save, pull city and state values from address based on standard address shipping name and populate city_and_state field (both are custom fields)
console.log is (obviously) just for checking, but always good practice
r is a collection variable in JSON (?) format that needs to be parsed to its message and fields (which was also pulled during frappe.call)
frappe.client.get_value is for client side scripting, while frappe.db.get_value is for server side scripting
frappe.ui.form.on('Sales Invoice', 'before_save', function(frm) {
frappe.call({
method:"frappe.client.get_value",
args: {
doctype:"Address",
filters: {
name: frm.doc.shipping_address_name
},
fieldname:["address_line1", "address_line2", "city", "state"]
},
callback: function(r) {
// console.log(r.message.address_line2);
var a = r.message.address_line1 + ', ' + r.message.address_line2;
var b = r.message.city + ', ' + r.message.state;
console.log(a);
console.log(b);
// set the returned value in the fields
cur_frm.set_value('address_1_and_2', a);
cur_frm.set_value('city_and_state', b);
}
})
});