Change field type programmatically

How can I change docfield type from Link to Text or Data.
I have tried this

frm.set_df_property(‘customer’, ‘fieldtype’, ‘Text’);

but it does not work for me.

Thanks advanced.

why do you want to do that?

I have field name customer this field can be a customer as a doctype to chose from customer doctype or even user can enter the name of customer as a text.

cant you use link field and make the user enter every customer name into customer master?

No, this is one case this field can be a Customer(doctype of Customer) and I need to change the datatype of this field to text.

Hi Jehad, Im still learning about ERPNext, but Im a senior programmer.

That doesnt seem right. Its prone to inconsistency, errors and lack of data tracing. It look like a design issue, not a technical challenge.

Tell us what you are trying to accomplish

My understanding of your requirement is that you would like to allow the user select a value from existing doctype (standard link) and also allow user to manually input the value but without the restriction of value exist in the linked doctype, if this is case, then the following code can give you some ideas, this code is extracted from my config-to-order app.

frappe.ui.form.make_control = function (opts) {
if (opts.df.fieldtype ==‘Data’ && opts.df.options===‘custom query’){
opts.df.ignore_link_validation= true;
opts.df.only_select = true;
opts.with_link_btn = false;
var control_class_name = “Control” + opts.df.fieldtype.replace(/ /g, “”);
if(frappe.ui.form[control_class_name]) {
return new frappe.ui.formcontrol_class_name;
} else {
// eslint-disable-next-line
console.log("Invalid Control Name: " + opts.df.fieldtype);

@JehadAlariqi were you able to solve the problem, I currently have the same problem