Try ERPNext Buy Support Partners Foundation

How to hide Dashboard link when Field data is changed

Hi there.

I want to figure out how to hide or show a Dashboard link when some Field in the DocType is changed.

So in example:

I got the standard Project DocType and ther is my Selectable field project_type.
When I select the second type of the Project then I want to hide some links at the top Dashboard, like a Material Request and so on.

Please let me know how to figure out.

Thanks.

One way I could think of achieving this is through a javascript tweak - project.js file
Add this function below the show_dashboard function -

project_type: function(frm) {
		if(frm.doc.project_type && frm.doc.project_type == 'Other') {
			$("[data-doctype='Material Request']").hide();
			$("[data-doctype='Purchase Order']").hide();
		} else {
			$("[data-doctype='Material Request']").show();
			$("[data-doctype='Purchase Order']").show();
		}
	}

Also you’ll need to add this in the onload function frm.trigger('project_type');
This might maybe give you some idea :+1:

1 Like

Hi. Thank you for the perfect solution.
I just need to check back what do you have told me.
I have added the desired code to my .js
When I’m good understand then this code will be fine, right?!

So it looks good, but. After a refresh the hidden links are come back.
Thats the problem. So it’s nearly a good solution but not 100%

I´d recommend that you change the event trigger (project_type) on line 55 to onload or refresh so it “triggers” when you load or refresh the document.

2 Likes

Hi, can you please visualise what you mean. I’m newbie so please show me what you mean. Thanks.

// posible hide link from dashboard
project_type: function(frm) {
if(frm.doc.project_type && frm.doc.project_type == ‘Tűzvédelem’) {
$("[data-doctype=‘Engine Repair Sheet’]").hide();
} else {
$("[data-doctype=‘Engine Repair Sheet’]").show();
}
frm.trigger(‘project_type’);
},

where to add this trigger?

Use it this way:

759

1 Like

I did mention inserting the trigger in onload :sweat_smile: , so that the links dont come back

Thank you Chabito79. Now works like a charm.
Another question. Can I replicate this function to another binded DocType? So I mean for another project_type with another hide?
Or I need to add it to this function too?

Just add it to any other doctype js file

Hi,

Do you know how to hide the labels?

I can’t figure how to.
Regards.

Can we Did this Using Custom Script ??

i used to hide supplier quotation button at Opportunity at below script, you can edit in your use case

frappe.ui.form.on('Opportunity', {
	refresh(frm) {
$("[data-doctype='Supplier Quotation']").hide();
}
});

How to do this on custom script?

How can I make a script to just remove the “+” and link on the dashboard but not hide it when the status of the project is already complete?

The “+” and the link on the dashboard doctypes leads to a bug. Because we can still create and submit a document eventhough the project is already tagged as completed.

Can you also help me?