Problem with populating the link field in the Child table

Hello Frappers,

I’m facing an issue where I’m populating a child table using a custom SQL query. This table includes a link field, a data field, and other types of fields. Even after refreshing the child table post-population, the link field continues to show the actual ID instead of the link field text. However, when I hover over the link field cell, the correct text appears.
Is there an alternative method for populating the link field and other fields?
I am using Frappe Framework: v15.x.x-develop on Debian

Screenshot before the population

Screenshot after population: Once the PO Template is selected, the child table is populated as shown below.

Here’s the source code for the population. The data is populated after the user selects the PO template, rather than during the onload or refresh events.

	po_template: function(frm) {
		if(frm.doc.po_template) {
			
			let po_template = frm.doc.po_template;
			let branch__id = frm.doc.branch_id;

			//-- frappe call start --
			frm.call({
				doc: frm.doc,
				method: 'get_raw_material',
				args: {
					po_template: po_template,
					branch: branch__id
				},
				freeze:true,
				freeze_message: "Processing",
				callback: function(r){
					if (r.message) {
						let msg = r.message;
						frm.doc.raw_material_from_template = [];
						if (msg.length == 0){
							frappe.show_alert("Raw materials are unavailable.");
						}
						else
						{
							$.each(msg, function(_i, e){
								let entry = frm.add_child("raw_material_from_template");
								//entry.raw_material = e[0];
								console.log('***********************************');
								console.log(e);
								//entry.raw_material =  parseInt(e[0]);
								entry.raw_material =  e[0];
								entry.unit = e[1];
								entry.price = e[2];
							});
						}
						frm.refresh_field("raw_material_from_template");
					}
				}
		    });
			//-- frappe call end --
		}
		else {
			console.log('po_template - failed ');
			frm.doc.raw_material_from_template = [];
			//refresh_field("raw_material_from_template");
		}
	},

Screenshot after population: The text appears when clicking on the link field cell.

At the same time, adding new items or editing existing ones in the link field works correctly.

Any help would be greatly appreaciated.

Thanks

When I click on the link field cell, it sends a request and retrieves the text for the link field. I suspect that the issue arises because I’m using Custom SQL, which may not be resolving the text correctly. Do you have any suggestions on how to force the link field to resolve it automatically?

http://rom_site:8000/api/method/frappe.desk.search.get_link_title

The custom SQL

  def get_raw_material(self, branch, po_template):
        print("inside python")
        print("branch")
        print(branch)
        print("po_template")
        print(po_template)
        sql = """
        SELECT chi.raw_material, chi.unit, chi.price
        FROM `tabPurchase Order Template` par
        INNER JOIN `tabPurchase Order Template Child` chi
        ON par.name = chi.parent
        WHERE par.branch_id = {} AND par.po_template = {}
        """
        sql = sql.format(branch, po_template)
        print(sql)
        item_data = frappe.db.sql(sql, as_dict=0)
        res_length = len(item_data)
        print(res_length)
        print(item_data)
        return item_data

The child table definition