How to create Custom Action in Link Field

I want to create a Custom Action in Link Field following Custom Action in Link Field this documentation. But where exactly write this code, I don’t understand. I already have this many ways in the doctype js file.
Like:

frappe.ui.form.ControlLink.link_options('test 2', {
	return [
        {
            html: "<span class="text-primary link-option">"
                + "<i class="fa fa-search" style="margin-right: 5px;"></i> "
                + __("Custom Link Option")
                + "</span>",
            label: __("Custom Link Option"),
            value: "custom__link_option",
            action: () => {}
        }
    ];
});

One more:

frappe.ui.form.ControlLink.link_options = function(link) {
    return [
        {
            html: "<span class="text-primary link-option">"
                + "<i class="fa fa-search" style="margin-right: 5px;"></i> "
                + __("Custom Link Option")
                + "</span>",
            label: __("Custom Link Option"),
            value: "custom__link_option",
            action: () => {}
        }
    ];
}

And many more ways I already try this. But I am not able to understand this coding process.
If any one know this process. Please help me.

Thanks

1 Like

Hi @Samsul,

How to use it to check the video.

Script:

frappe.ui.form.ControlLink.link_options = function(link) {
    if (link.df.fieldname === "item_group") {
        return [
            {
                html: "<span class='text-primary link-option'>"
                    + "<i class='fa fa-search' style='margin-right: 5px;'></i> "
                    + __("Custom Link Option")
                    + "</span>",
                label: __("Custom Link Option"),
                value: "custom__link_option",
                action: () => {
                    frappe.msgprint("Custom link option clicked!");
                }
            }
        ];
    }
};

I hope this helps.
Thank You!

2 Likes

Add Your code on the Client Script docype with.

1 Like

Thanks, It work