How to populate Contact phone when the contact is selected while creating a ticket

Hey guys how can i populate contact phone field automatically when the contact is selected while on the HD Ticket page. Here’s the code i used on client script;
frappe.ui.form.on(‘HD Ticket’, {
contact: function(frm) {
if(frm.doc.contact) {
frappe.call({
method: ‘frappe.client.get’,
args: {
doctype: ‘Contact’,
name: frm.doc.contact
},
callback: function(response) {
if(response.message) {
var contact = response.message;
var phoneNumber = contact.phone || contact.mobile_no || ‘’;
frm.set_value(‘phone’, phoneNumber);
if (phoneNumber) {
frappe.show_alert({message: ‘Phone number updated’, indicator: ‘green’});
} else {
frappe.show_alert({message: ‘No phone number found for this contact’, indicator: ‘orange’});
}
}
}
});
}
}
});

but i’m getting “Phone field not found”.

@Sirmuel I think you can use fetch from field that will directly fetch contact phone from selected contact

I used link type doc but it still not fetching, kindly guide on steps you used for yours

This error suggests that there is no such field as “Phone” in your doctype. If this is a custom field, then the name will be something like custom_phone because there is no such field as “Phone” in the HD Ticket Doctype by default.

I set it up based on these parameters, the contact where it should pick from

And the ticket section

  1. What is the name of your Phone field in the database (is it phone or custom_phone)?
  2. In my opinion, you can use the “fetch from” for your Phone field in the HD Ticket doctype.?

it was “custom_phone” thank you

1 Like