How to add a column in custom script

Hi guys,

I am exploring the education domain and I would like to add a new DocType for units per course.

So how can I add the units per course… Can someone explain to me how can i generate a custom scripts for this total… I am referring to this code that add up all the qty of all items…

frappe.ui.form.on("Stock Entry", "refresh", function(frm, cdt, cdn) {
    // code for calculate total and set on parent field.
    total_qty = 0;
    $.each(frm.doc.items || [], function(i, d) {
    total_qty += flt(d.qty);
    });
    frm.set_value("total_qty", total_qty);
    });

Code seems to be fine, instead of refresh do it on validate

frappe.ui.form.on("Stock Entry", "validate", function(frm, cdt, cdn) { })

sir if i made a new doctype for that code… example General Schedule do i have change the code like this
frappe.ui.form.on(“General Schedule”, “refresh”, function(frm, cdt, cdn) {…

Yes thats right.

In general - frappe.ui.form.on("DocType Name", "fieldname or standard function", function(frm, cdt, cdn) { })

sir can you help me with my code its not working at all… i very confuse about it…it seems my loop has the a wrong field name… i cant actual find what wrong on the my code… please do help me…

frappe.ui.form.on("General Schedule", "refresh", function(frm, cdt, cdn) {
    // code for calculate total and set on parent field.
    total_units= 0;
    $.each(frm.doc.items|| [], function(i, d) {
    total_units += flt(d.qty);
    });
    frm.set_value("total_units", total_units);
    });

//i also try this code: i change the doc.items in the loop the  item to subject and units instead of qty. please help me..

frappe.ui.form.on("General Schedule", "validate", function(frm, cdt, cdn) {
    // code for calculate total and set on parent field.
    total_units= 0;
    $.each(frm.doc.subject|| [], function(i, d) {
    total_units += flt(d.units);
    });
    frm.set_value("total_units", total_units);
    });



print total_units in console and check is it actully work or not like console.log(total_units);

im actually running in a vmware… how can i run in a console?

you just write
console.log(total_units)
and check in browser console tab using F12

This is the result on the console when i type on the console

VM130:1 Uncaught ReferenceError: total_units is not defined
at :1:13
(anonymous) @ VM130:1

use this

frappe.ui.form.on(“General Schedule”, “refresh”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
var total_units= 0;
$.each(frm.doc.items|| [], function(i, d) {
total_units += flt(d.qty);
});
frm.set_value(“total_units”, total_units);
});

it bounce an error…

SyntaxError: Invalid or unexpected token
    at Class.setup (http://localhost:8040/assets/js/form.min.js?ver=1522523161.0:2693:18)
    at _f.Frm.setup (http://localhost:8040/assets/js/form.min.js?ver=1522523161.0:172:22)
    at _f.Frm.refresh (http://localhost:8040/assets/js/form.min.js?ver=1522523161.0:446:9)
    at Class.load (http://localhost:8040/assets/js/form.min.js?ver=1522523161.0:87:33)
    at http://localhost:8040/assets/js/form.min.js?ver=1522523161.0:82:7
    at Object.callback (http://localhost:8040/assets/js/desk.min.js?ver=1522523161.0:5516:6)
    at Object.callback [as success_callback] (http://localhost:8040/assets/js/desk.min.js?ver=1522523161.0:1437:16)
    at _ (http://localhost:8040/assets/js/desk.min.js?ver=1522523161.0:1461:34)
    at Object. (http://localhost:8040/assets/js/desk.min.js?ver=1522523161.0:1562:5)
    at i (http://localhost:8040/assets/frappe/js/lib/jquery/jquery.min.js:2:27151)