Hi i have a custom field in Item Module “price_valid_to” . I want the data of “Valid Upto” from item price module to the custom field “price_valid_to” on item module.
Thank you guys in advance
Hi i have a custom field in Item Module “price_valid_to” . I want the data of “Valid Upto” from item price module to the custom field “price_valid_to” on item module.
Thank you guys in advance
Hi, you will have to write a client script to bring the value, however an item can have multiple price list associated with it.
This code will bring the result you need. If you have to bring the value from a specific price list then you need add that price list as a variable and pass it in args filter.
frappe.ui.form.on('Item', {
refresh: function(frm) {
fetchValidUpto(frm);
}
});
function fetchValidUpto(frm) {
frappe.call({
method: 'frappe.client.get_value',
args: {
doctype: 'Item Price',
filters: {
item_code: frm.doc.item_code,
},
fieldname: ['valid_upto']
},
callback: function(response) {
if (response.message && response.message.valid_upto) {
frm.set_value('custom_price_valid_to', response.message.valid_upto);
} else {
frappe.msgprint('Valid Upto not found for the selected price list.');
}
}
});
}
Thank you so much, Yes i have multiple pricelist but i only want to the pricelist named “Product Cost”
In that case just add price list name in the filter,
frappe.call({
method: 'frappe.client.get_value',
args: {
doctype: 'Item Price',
filters: {
item_code: frm.doc.item_code,
price_list: "Product Cost",
},
fieldname: ['valid_upto']
},
frappe.ui.form.on(‘Item’, {
refresh: function(frm) {
fetchValidUpto(frm);
}
});
function fetchValidUpto(frm) {
frappe.call({
method: ‘frappe.client.get_value’,
args: {
doctype: ‘Item Price’,
filters: {
item_code: frm.doc.item_code,
price_list: “Product Cost”,
},
fieldname: [‘valid_upto’]
},
callback: function(response) {
if (response.message && response.message.valid_upto) {
frm.set_value(‘custom_valid_until’, response.message.valid_upto);
} else {
frappe.msgprint(‘Valid Upto not found for the selected price list.’);
}
}
});
}
I dont know what is wrong that is the script that i used
Hi @xchicox,
The script you provided looks mostly correct, but there’s a small issue in the frm.set_value
line. You are trying to set the value of a custom field called “price_valid_to,” but in your code, you’re using the fieldname “custom_valid_until.” To fix this, make sure the fieldname you use matches the name of the custom field in the Item Module. Here’s the corrected script:
frappe.ui.form.on('Item', {
refresh: function(frm) {
fetchValidUpto(frm);
}
});
function fetchValidUpto(frm) {
frappe.call({
method: 'frappe.client.get_value',
args: {
doctype: 'Item Price',
filters: {
item_code: frm.doc.item_code,
price_list: 'Product Cost',
},
fieldname: ['valid_upto']
},
callback: function(response) {
if (response.message && response.message.valid_upto) {
frm.set_value('price_valid_to', response.message.valid_upto);
} else {
frappe.msgprint('Valid Upto not found for the selected price list.');
}
}
});
}
Please check/set the doctype and field name and then reload and check it.
I hope this helps.
Thank You!
thank you so much, It worked however it happens that i need to re enter the date in valid_upto again in able to have the date in price_valid_to and it didnt save automatically as well.
Could you please help me on that, to automatically add the data instead of me changing it before it shows and also to auto save it in Item module once the date being fetched.
thank you in advance
if (response.message && response.message.valid_upto) {
frm.set_value('price_valid_to', response.message.valid_upto);
frm.save()
}
Please apply it and check it.
Thank You!
thank you it worked .