Total field custom script

I’ve coded child table for total calculating percentage of all rows.
i want to changing its color to RED if it gets greater than 100.
please anybody can help me up?
below is my code and SS.

frappe.ui.form.on(“Partnership”, “partnership_percent”, function(frm, cdt, cdn) {

var calculate = frm.doc.partnership_information;
var total = 0
for(var i in calculate) {
total = total + calculate[i].partnership_percent

if(frm.doc.total_percentages >100)
	frappe.msgprint("Total Percentage Cannot be Greater Than 100%")



You could catch the html element of the field with javacript/jquery and add the css style properity “background-color: red” to it…

Thanks for your reply @joelios
I’ve tried below code but didn’t work.
Please tell me where i am wrong.

if(frm.doc.total_percentages >100)
frappe.msgprint(“Total Percentage Cannot be Greater Than 100%”)
frm.set_value(“total_percentages”, <span style=“color:red” + frm.doc.total_percentages + );

  • );

That could maybe work with an html field, but not with a data…

In your customscript, you have to select the corresponding html element like “var field = documemt.getElementById(“id of field”);”
Afterward you could add the css properity to iz with for e.g. “ = “red”;”

You are talking about to get element by id? from where can i get its id?
I tried get element by name but didn’t work.

if(frm.doc.total_percentages >100)
frappe.msgprint(“Total Percentage Cannot be Greater Than 100%”)
document.getElementsByName(“total_percentages”).style.background-color = “red”;

with getElemetsByName you will get a list of all html element with the searched class name, this can not work…

Unfortunalty i’m not at home, as soon as im at home i will send you a customscript that will work…

Thank you so much @joelios
i am waiting.

hi @shahid sorry for my late feedback.

try this script, it should work:

if (frm.doc.total_percentages >100) {
 frappe.msgprint(“Total Percentage Cannot be Greater Than 100%”);

please let me know if its worked.


@joelios it is not working. :confused:

Sorry i had an typo in it, ‘total_percentages’ instead of ‘total_percentage’… :wink:

Please replace the wrong fieldname with the correct one and it will work :wink:

@joelios it is total_percentages.

Hm strange, it works on my testsystem :thinking:

Can you show me your browser consol errors?

Sorry? console errors?
where it is i don’t know.

Press F12 in your browser and select console, there you’ll find all javascript based errors

jquery.min.js:4 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help, check
send @ jquery.min.js:4
libs.min.js?ver=1516030925.0:7295 WebSocket connection to ‘ws://’ failed: Error during WebSocket handshake: Invalid status line
n.doOpen @ libs.min.js?ver=1516030925.0:7295

Ok, there is no error based on this script.

Does the frappe.msgprint message shows up?

Yes it is showing. and all code is working fine.

should we have to use !important property ??