cuztomize field script

195 views
Skip to first unread message

Bobby Hartanto

unread,
Sep 27, 2014, 3:03:24 AM9/27/14
to erpnext-dev...@googlegroups.com
Hi,



i just created field standard in my BOM item table , and i want to add
script that when i fill the value of standard field the qty field will be
updated as (BOM quantity * standard value)
how can i do this ?
i know how to add script but i dont know what to write.... :(



Thanks,
Bobby

Saurabh Palande

unread,
Sep 27, 2014, 5:39:27 AM9/27/14
to erpnext-dev...@googlegroups.com
Hi Bobby,

Just add trigger on custom field,

eg: 
cur_frm.cscript.field_name = function(doc,cdt,cdn){
     var d = local[cdt][cdn];
     ------- your code ---------
}

Please consider following link for reference



Generally we use cur_frm.set_vaue() to set result to output field and then use refresh_field() to refresh the field.


Regards,

--
1. Please be kind and don't send large attachments
2. For issues, features requests use https://github.com/frappe/erpnext/issues
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/111ea0e4-e8ab-4af3-a994-c225ca2a9c0a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
S.S.Palande

Bobby Hartanto

unread,
Sep 28, 2014, 12:32:19 AM9/28/14
to erpnext-dev...@googlegroups.com
Hi Thanks,



but please inform me , what is the param of refresh_field() ....


Thanks
Bobby
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsub...@googlegroups.com.



--
S.S.Palande

Rushabh Mehta

unread,
Sep 28, 2014, 1:17:01 AM9/28/14
to erpnext-dev...@googlegroups.com
On 28-Sep-2014, at 10:02 am, Bobby Hartanto <bobzz...@gmail.com> wrote:

Hi Thanks,



but please inform me , what is the param of refresh_field() ....

Should be refresh_field(fieldname)

you can also use - this will also refresh the field

cur_frm.set_value(fieldname, value)


To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/f95c9c2e-aced-4bc8-a428-8ca663ec8f14%40googlegroups.com.

Bobby Hartanto

unread,
Sep 28, 2014, 3:00:47 AM9/28/14
to erpnext-dev...@googlegroups.com
Hi Rusabh thanks,


now im confused about ...this part in this script :
i want to change field qty in BOM_materials table when im set the standard value in BOM_materials
which the value of qty is standard * quatity in BOM

i can read bom quantity by calling doc.quantity (since im doing this in BOM script) , but i dont know how i can call the standard filed and qty field which is in the BOM_Materils
please advise ...


Thanks
To unsubscribe from this group and stop receiving emails from it, send an email toerpnext-developer-forum+unsubsc...@googlegroups.com.



-- 
S.S.Palande

-- 
1. Please be kind and don't send large attachments
2. For issues, features requests use https://github.com/frappe/erpnext/issues
--- 
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsub...@googlegroups.com.

Saurabh Palande

unread,
Sep 28, 2014, 7:37:59 AM9/28/14
to erpnext-dev...@googlegroups.com
HI Bobby,

If field is on child table then use,

var d = local[cdt][cdn]
d.field_name

Regards,

To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6e380952-a82d-4082-80ca-bc70396b671f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
S.S.Palande

Bobby Hartanto

unread,
Sep 28, 2014, 8:16:47 AM9/28/14
to erpnext-dev...@googlegroups.com
Hi,


what is cdt & cdn ? for better understanding


Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubsc...@googlegroups.com.

--
1. Please be kind and don't send large attachments
2. For issues, features requests use https://github.com/frappe/erpnext/issues
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsub...@googlegroups.com.



--
S.S.Palande

Saurabh Palande

unread,
Sep 28, 2014, 8:19:36 AM9/28/14
to erpnext-dev...@googlegroups.com
Hi,

cdt stands for "Child DocType" 
cdn stands for "Child Doc Name" 

Regards,

To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/bdba6240-97b2-43cd-95c2-814cc2a29560%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
S.S.Palande

Bobby Hartanto

unread,
Sep 29, 2014, 3:19:38 AM9/29/14
to erpnext-dev...@googlegroups.com
Hi,


im tried this:
cur_frm.cscript.standard = function(doc,dt,dn) {
var d=local[dt][dn];
var q = doc.quantity;
var qty=local[dt]["qty"];
qty=q*d;
refresh_field(qty);
}

but it didnt work, web console said that local is undifined
please advise

Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr...@googlegroups.com.



--
S.S.Palande

--
1. Please be kind and don't send large attachments
2. For issues, features requests use https://github.com/frappe/erpnext/issues
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsub...@googlegroups.com.



--
S.S.Palande

Saurabh Palande

unread,
Sep 29, 2014, 3:44:08 AM9/29/14
to erpnext-dev...@googlegroups.com
Hi,

On Mon, Sep 29, 2014 at 12:49 PM, Bobby Hartanto <bobzz...@gmail.com> wrote:
Hi,


im tried this:
cur_frm.cscript.standard = function(doc,dt,dn) {
var d=local[dt][dn];
var q = doc.quantity;
var qty=local[dt]["qty"];

d = locals[cdt][cdn], provides you child table's row object, hence no need to create it twice

To access the fields use d.standard and d. qty.

 
qty=q*d;

for multiplication use flt(doc.quantity)*flt(d.standard) 


refresh_field(qty);

for setting up value and refreshing ref following link


  
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/03ac2863-8eff-42a1-9bd9-418c306434f9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
S.S.Palande

Bobby Hartanto

unread,
Sep 29, 2014, 8:37:30 AM9/29/14
to erpnext-dev...@googlegroups.com
Hi,



please tell me, what was it the params that needed by refresh_field..

im quite confused about it

im tried refresh_field("qty")  to refresh qty value in materials table but its not working

Thanks

You received this message because you are subscribed to a topic in the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/erpnext-developer-forum/X_Bcm5n-cHo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CAGCrPP-HpDtuSikso4xWDKwF6pS0TCjA8XCPeTiPjb6wHuyYRw%40mail.gmail.com.

Saurabh Palande

unread,
Sep 29, 2014, 9:28:44 AM9/29/14
to erpnext-dev...@googlegroups.com
Hi Bobby,

Syntax:
refresh_field('field_name', row_name, 'child_table_name')

Ref below link:
 
Regards,


For more options, visit https://groups.google.com/d/optout.



--
S.S.Palande

Bobby Hartanto

unread,
Sep 29, 2014, 9:42:36 AM9/29/14
to erpnext-dev...@googlegroups.com
Hi,

since this local or client scripting i think there is no row name , am i right ?
in the end i placed my script like this
cur_frm.csript.standard = function(doc,dt,dn){
var d = locals[dt][dn];
d.qty=flt(d.standard)*flt(doc.quantity);
refresh_field("qty",d.qty,"bom_materials");
}
but its not working ... nothing happend when i type in standard field
what am i mistaking ?
its giving me error "cur_frm.fields_dict[table_field].grid.grid_rows_by_docname[docname]"

Thanks

Anand Doshi

unread,
Sep 29, 2014, 9:43:59 AM9/29/14
to ERPNext Developer's Forum
Did you add this Custom Script in "BOM" doctype?

-Anand.

Saurabh Palande

unread,
Sep 29, 2014, 9:54:56 AM9/29/14
to erpnext-dev...@googlegroups.com
Hi Bobby,

instead of d.qty use d.name at second position  in refresh_field method

Regards,


For more options, visit https://groups.google.com/d/optout.



--
S.S.Palande

Bobby Hartanto

unread,
Sep 29, 2014, 10:27:28 AM9/29/14
to erpnext-dev...@googlegroups.com
Hi Saurabh,

its working.... thanks...

Anand, Yes i doing it in BOM doctype....

Thanks,
Bobby

Reply all
Reply to author
Forward
0 new messages