Queries regarding Custom Scripts

519 views
Skip to first unread message

Aditya Duggal

unread,
Feb 25, 2013, 5:38:55 AM2/25/13
to erpnext-dev...@googlegroups.com
Hi,

I have some queries with regards to custom scripts:

  1. I am trying to make certain fields in the item master as "READ-ONLY" but after the creation of item codes. Since my item codes would be dependent on these fields and to maintain the integrity of the items I would like to lock these fields using the custom script. Kindly let me know how to achieve this by using custom reports.
  2. Is there a way to show certain fields on screen at the time of item creation since they are the ones according to which the item code is created, something on the lines of the item variant which is long pending but now I am trying to prepare one myself.


Rushabh Mehta

unread,
Feb 27, 2013, 12:44:12 AM2/27/13
to erpnext-dev...@googlegroups.com
Aditya,

Check the first example:


You can also use this to set the "hidden" property of docfield (df).

best,
Rushabh


W: https://erpnext.com
T: @rushabh_mehta

--
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 post to this group, send email to erpnext-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/roI6wXRFBVIJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Aditya Duggal

unread,
Apr 1, 2013, 6:23:26 AM4/1/13
to erpnext-dev...@googlegroups.com
Hi Rushabh,

Thanks for the code.

But one more thing which seems to be missing is that there is no code to know how to update the field value in a particular form.

I would be able to fetch a value from the item group via the code mentioned here

But what if  I need to update that value to a new updated value, the code for that is not mentioned in the scripting.



On Wednesday, February 27, 2013 11:14:12 AM UTC+5:30, rushabh wrote:
Aditya,

Check the first example:


You can also use this to set the "hidden" property of docfield (df).

best,
Rushabh


W: https://erpnext.com
T: @rushabh_mehta

On 25-Feb-2013, at 4:08 PM, Aditya Duggal <aditya...@gmail.com> wrote:

Hi,

I have some queries with regards to custom scripts:

  1. I am trying to make certain fields in the item master as "READ-ONLY" but after the creation of item codes. Since my item codes would be dependent on these fields and to maintain the integrity of the items I would like to lock these fields using the custom script. Kindly let me know how to achieve this by using custom reports.
  2. Is there a way to show certain fields on screen at the time of item creation since they are the ones according to which the item code is created, something on the lines of the item variant which is long pending but now I am trying to prepare one myself.



--
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.

Nabin Hait

unread,
Apr 1, 2013, 6:37:14 AM4/1/13
to erpnext-dev...@googlegroups.com
Hi,

You can set the returned value in callback function, I had updated the wiki (https://github.com/webnotes/wnframework/wiki/Client-side-scripting#get-values-from-server). 


Regards,
Nabin Hait

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

To post to this group, send email to erpnext-dev...@googlegroups.com.

Aditya Duggal

unread,
Apr 1, 2013, 6:53:14 AM4/1/13
to erpnext-dev...@googlegroups.com
Thanks Nabin

I have one more query which I have posted in stackoverflow maybe it might interest you regarding the creation of an alphanumeric key, the link for the question is this

Aditya Duggal

unread,
Apr 1, 2013, 9:09:47 AM4/1/13
to erpnext-dev...@googlegroups.com
Hi,

I am almost there with this custom script and its understanding but currently I am having an issue with the client side script. Can you please let me know what is the error in this client script

What is this script doing?
  • Fetch values from the item group selected line 1~8
  • Function to generate the alphanumeric key line 11~17
  • Code to disable fields after saving line 19~24
  • Fetch the field serial_number mentioned in the item group selected and then assign the item code with that serial number line 26~48
  • Update the serial number with the next value in the series in the ITEM GROUP which has been selected line 50~56

Kindly let me know what is wrong with the code since I am unable to perform the tasks mentioned in the code.

Aditya Duggal

unread,
Apr 2, 2013, 2:37:50 AM4/2/13
to erpnext-dev...@googlegroups.com
Hi,

I have update the code in the gist the updated code is here. Now the code is working fine but the only things which are not working are:
  • I am unable to fetch Serial Number properly from the Item Group in a Item Code
  • Unable to update the serial number in the item group of the item.
  • Also I am facing a peculiar problem, if for some reason the item is not saved the counter of the serial number still keeps on running so if the serial number is 111 and if we face the did not save error for 3 times then the next time the serial number becomes 115 instead of 111. So the code is not exiting at the time of the did not save.

Kindly please help me with the small modifications so that I could continue with my work.

Aditya Duggal

unread,
Apr 2, 2013, 9:08:50 AM4/2/13
to erpnext-dev...@googlegroups.com
Another thing I wanted to know which is not mentioned in the wiki is that what code should I use if I want a code to be initiated only at the time of creating a document currently I am using some code under

cur_frm.cscript.custom_validate = function(doc) {

But this code also runs if I make some changes to an existing document, whereas my need is to run some particular code only at the time of creation of the document.

Is there any solution for that?

Anand Doshi

unread,
Apr 2, 2013, 9:12:01 AM4/2/13
to erpnext-dev...@googlegroups.com
Use this in custom_validate

if(cur_frm.doc.__islocal) {
    // your code here
}

Sent from my phone
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.

To post to this group, send email to erpnext-dev...@googlegroups.com.

Aditya Duggal

unread,
Apr 2, 2013, 9:57:41 AM4/2/13
to erpnext-dev...@googlegroups.com
Thanks Anand for the quick response. Works like a jiffy.

Also where can I access all the coding options of wnframework since I need to know if I could control a code to run only after successful saving of a document since my counter seems to be running even if there is an error in saving a new document.

Anand Doshi

unread,
Apr 2, 2013, 10:18:16 AM4/2/13
to erpnext-dev...@googlegroups.com
Hi Aditya 

Developer documentation needs a lot of work. It's one of the items which we are gonna take up next since auto inventory accounting is almost done. 

I think you can try using 

cur_frm.cscript.after_save = function() {

}

I am not so sure about it. Will need to check the code since it is rarely used. 

Sent from my phone
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.

To post to this group, send email to erpnext-dev...@googlegroups.com.

Anand Doshi

unread,
Apr 2, 2013, 10:39:11 AM4/2/13
to Anand Doshi, erpnext-dev...@googlegroups.com
Hi Aditya,

Scratch that. I think I have a better solution to your item code woes. It is about playing a trick on the naming series system. 

Hopefully, it should work. You can try this out in your test environment:

1. Create a custom field in item with label "Naming Series" and field type = "Data".
It will create a field with field name = "naming_series". (You may mark it as Mandatory after testing if it works)

2. In your URL, type this after app.html - "#List/Property Setter".
Click on New to create a new Property Setter and enter the following:
DocType or Field = DocType
DocType = Item
Property = auto name
Property Type = Data
Set Value = naming_series:

make sure to type that colon at the end of naming_series

Save this Property Setter

3. So now that the ground is set, all you have to do is before saving (in custom_validate), make sure that Naming Series is set to your codification system like ITEM_GROUP_NAME-SOME_OTHER_VARIABLE-
and when saving, it will keep track of the number for that series ITEM_GROUP_NAME-SOME_OTHER_VARIABLE-

So, if you are saving the first item of the series, ITEM_GROUP_NAME-SOME_OTHER_VARIABLE- then it will be named as ITEM_GROUP_NAME-SOME_OTHER_VARIABLE-00001

The only constraint here is that the number will be of 5 digits, since this is the way naming series works in ERPNext.

I think it is a better way to keep track of your series instead of updating Item Group after saving every Item.

Hope this helps.

Thanks,
Anand.

Aditya Duggal

unread,
Apr 2, 2013, 11:01:42 AM4/2/13
to erpnext-dev...@googlegroups.com, Anand Doshi
Hi Anand,

Thanks for the earlier suggestion of after save it works as always. As for the naming series system, I have come up with a new naming system which is very small, I am more inclined in using the  3 digits for the serial number so that the item code remains small. My target is to get the item codes to less than 10-digits or at max 10 digits with a check digit for which I would be posting a query.

I guess with these constraints I cannot go for numeric serial number since 5-digit numeric serial number only saves 99,999 records whereas with alphanumeric series I could save 46,656 (36^3) records in just 3 digits. Also I am planning to remove the confusing letters or digits vis-a-vis I,O and 0. Which means I can store upto 35,937 (33^3) records in 3 digit serial number.

Also this new item coding which I am planning should be sufficient for my company even if we go beyond a million item codes and I am hoping that this project of sorts would be a one time effort for a long time to come. I am planning to share this thing in a blog once I am satisfied with things since with my case I am the coder and the user as well.

I hope there must be a way to manage the series via item group.....please don't tell me that it is not possible since I am banking on this part of the code and I am continuing my work, hoping that I would get a solution from your end in a day or two.

Nabin Hait

unread,
Apr 2, 2013, 2:15:01 PM4/2/13
to erpnext-dev...@googlegroups.com, Anand Doshi
Hi Aditya,

Instead of doing client side scripting, if you do it in server side script (python), then life will be lot easier. 

I have made a gist, it will do the trick, please check this link https://gist.github.com/nabinhait/5294657

Regards,
Nabin Hait

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

To post to this group, send email to erpnext-dev...@googlegroups.com.

Aditya Duggal

unread,
Apr 2, 2013, 11:31:08 PM4/2/13
to erpnext-dev...@googlegroups.com, Anand Doshi
Hi Nabin,

Thanks for the gist, now I would need to do some searching on Python but before I do that I think with new updates the option to create server side scripting has been disabled. Kindly let me know how could I create custom script on server side.

Aditya Duggal

unread,
Apr 9, 2013, 4:21:40 AM4/9/13
to erpnext-dev...@googlegroups.com, Anand Doshi
Hi Nabin,

Tried to run this code on my test account and I am getting a error in loading a script whch says "Error in script while loading" when I click on an item. The error code I am getting is as below:

[13:43:06.051] Traceback (innermost last):
  File "../lib/webnotes/widgets/form/load.py", line 83, in load_single_doc
    dl = webnotes.bean(dt, dn).doclist
  File "../lib/webnotes/__init__.py", line 307, in bean
    return Bean(doctype, name)
  File "../lib/webnotes/model/bean.py", line 54, in __init__
    self.load_from_db(dt, dn)
  File "../lib/webnotes/model/bean.py", line 80, in load_from_db
    self.run_method("onload")
  File "../lib/webnotes/model/bean.py", line 214, in run_method
    self.make_obj()
  File "../lib/webnotes/model/bean.py", line 103, in make_obj
    self.obj = webnotes.get_obj(doc=self.doc, doclist=self.doclist)
  File "../lib/webnotes/__init__.py", line 292, in get_obj
    return get_obj(dt, dn, doc, doclist, with_children)
  File "../lib/webnotes/model/code.py", line 156, in get_obj
    return get_server_obj(doc, doclist)
  File "../lib/webnotes/model/code.py", line 108, in get_server_obj
    exec custom_class + custom_script.replace('\t','  ') in locals()
  File "<string>", line 29
    return strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(s) - len(strip_zs))
         ^
 IndentationError: expected an indented block

Traceback (innermost last):
  File "../lib/webnotes/handler.py", line 156, in handle
    execute_cmd(cmd)
  File "../lib/webnotes/handler.py", line 191, in execute_cmd
    ret = call(method, webnotes.form_dict)
  File "../lib/webnotes/handler.py", line 208, in call
    return fn(**newargs)
  File "../lib/webnotes/widgets/form/load.py", line 43, in getdoc
    doclist = load_single_doc(doctype, name, user or webnotes.session.user)
  File "../lib/webnotes/widgets/form/load.py", line 87, in load_single_doc
    raise e
  File "<string>", line 29
    return strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(s) - len(strip_zs))
         ^
 IndentationError: expected an indented block

Also I would like to ask a few more questions:
  1. if it is possible to fetch the field entered by the user in the server script then I would easily be able to generate the item code.
  2. how could I change the above code to only generate 3-digit series only using numbers 1-9 and capital letters. Please note that I am planning to omit the following characters from the item code 0 (Zero), I and O.

I am sorry to ask so many simple questions since this is the first time I have had my tryst with Python code anyhow I have already started to read about python code as well now. Hope you would show me the right path to follow.

Nabin Hait

unread,
Apr 9, 2013, 7:59:46 AM4/9/13
to erpnext-dev...@googlegroups.com
Hi Aditya,

In python, "Indentation" is very important, based on that it decide the block of statements. Please check the indentation.

And you should use either Space or Tab, for indentation.

You can fetch any value entered by the user in server script, using self.doc.fieldname

Excluding uppercase letters and I, O, 0 is very difficult to implement, it breaks normal alphanumeric addition. Regarding 3 digit naming, you are entering the serial no in item group manually, so try to limit to 3 digit there.



Regards,
Nabin Hait

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

To post to this group, send email to erpnext-dev...@googlegroups.com.

Aditya Duggal

unread,
Apr 9, 2013, 1:18:34 PM4/9/13
to erpnext-dev...@googlegroups.com
Hi Nabin,

I have been able to get rid of the error, thanks you for the code. I think there seems to be a problem with the next serial code since my item codes are not getting the next serial number after the code. Also I have added the code to add a check digit at the end of the item code which might be creating some problem kindly let me know what have I done wrong. I have updated the gist with a fork here.

Regards,
Nabin Hait

Aditya Duggal

unread,
Apr 17, 2013, 4:12:05 AM4/17/13
to erpnext-dev...@googlegroups.com
Is it possible to make a field mandatory based on its visibility? I have certain fields which become hidden or visible based on eval property of customise form view.

Now what I want is that a field becomes mandatory if it is visible. Kindly let me know if this kind of a thing is possible.

Anand Doshi

unread,
Apr 17, 2013, 4:15:25 AM4/17/13
to erpnext-dev...@googlegroups.com
Hi Aditya,

Why not shift the conditions from depends_on to custom script? That way you can specify to display and make it mandatory in one shot.

Thanks,
Anand.

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

To post to this group, send email to erpnext-dev...@googlegroups.com.

Aditya Duggal

unread,
Apr 18, 2013, 3:39:07 AM4/18/13
to erpnext-dev...@googlegroups.com
Another Small query, how do I set the default value of a field on loading of a form. Basically, I want to remove old data entered if a certain field is hidden so that the old does not get into the table creating redundant data.

Also I would like to show some pictures based on the selection field. Is it possible to fetch some picture based on a field change.

Rushabh Mehta

unread,
Apr 19, 2013, 12:35:30 AM4/19/13
to erpnext-dev...@googlegroups.com

> Another Small query, how do I set the default value of a field on loading of a form. Basically, I want to remove old data entered if a certain field is hidden so that the old does not get into the table creating redundant data.

Every field has a "default" property - you can set it in Customize Form View

> Also I would like to show some pictures based on the selection field. Is it possible to fetch some picture based on a field change.

In Image field, in the options property, set the fieldname of the image url.

To make a file "Select" set, "attach_files:" in the options property.

(See "Item" for how its done)

Aditya Duggal

unread,
Apr 19, 2013, 2:56:59 AM4/19/13
to erpnext-dev...@googlegroups.com
Hi Rushabh,

Thanks for the suggestion, basically regarding the default values, they only work in case a new transaction or master is being made vide the make new option. But the defaults does not load if we copy an existing transaction or master and for that thing there is no copy which is not accessible to users, even if I make the changes directly to the doctype then I know that the fields would be reset to the default once an update come.

As for the attaching of image automatically, I was not able to find the part in the item.js but I was able to find something on the wiki and I am using this to update the image on client side by using the below code but it does not update the same, let me know what is wrong since the error I am receiving is 

[12:00:14.344] ReferenceError: file_list is not defined @ http://test.rigpl.com/js/all-app.min.js:2477

The code is here.

Also is there a way to change the size of the image place holder since the default size of the image place holder is small for the purpose for which I am using. If we cannot change the default image placeholder size then is it possible to add a custom field of image placeholder and change the size either via customise form view or via a script.

Anand Doshi

unread,
Apr 19, 2013, 3:56:42 AM4/19/13
to erpnext-dev...@googlegroups.com
Hi Aditya,

NO COPY
You can use write code to clear desired fields in:
cur_frm.cscript.custom_onload = function() {
var fields = ["field1", "field2"];
for(var i in fields) {
cur_frm.set_value(fields[i], "");
}
};

FILE LIST
We are going to release a file manager and we have changed a lot of code. Can you wait for next week for this customisation? It will avoid repetition of work.

Also, you will need to write server side code for this.

PLACEHOLDER
Such a feature is not a priority. Also, I am unable to understand why do you want this feature. If you intend to print the item's page, better make a custom Print Format and specify the size in it. Playing with the form elements can only cause problems in future, when we do any changes in the layout.


Thanks,
Anand.

--
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 post to this group, send email to erpnext-dev...@googlegroups.com.

Aditya Duggal

unread,
Apr 19, 2013, 5:07:39 AM4/19/13
to erpnext-dev...@googlegroups.com
Hi Anand,

Thanks you very much for the NO COPY code it should solve a lot of problems for me. As for the file list I can definitely wait and I guess I would be letting it sleep till the time new release are made and as for the image placeholder I think Umair gave me a very simple solution of opening the attachment which I don't know why I did not think of and hence I guess the placeholder part is also done.

Once again thanks a lot for all the help you people have been offering.

Aditya Duggal

unread,
Apr 26, 2013, 6:11:08 AM4/26/13
to erpnext-dev...@googlegroups.com
Hi,

I need to pull an image in a print format from a different doctype. I have tried using this 

<script>webnotes.client.get_value("Tool Type", doc.tool_type, "image")</script>

But this is not helping me out can you suggest a code hidden in the client side so that I could fetch a photo attached to a doctype.

Rushabh Mehta

unread,
Apr 26, 2013, 7:52:32 AM4/26/13
to erpnext-dev...@googlegroups.com
Aditya,

webnotes.client.get_value is a server side function.

You will need the value (tool_type_image) in your current transaction using add_fetch

Then use an image tag like:

<script>"<img src='" + doc.tool_type_image + "' />"</script>

This should work...

best,
Rushabh




W: https://erpnext.com
T: @rushabh_mehta

--
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 post to this group, send email to erpnext-dev...@googlegroups.com.

Aditya Duggal

unread,
Apr 26, 2013, 10:44:43 AM4/26/13
to erpnext-dev...@googlegroups.com
Thanks rushabh,

It works perfectly. Just one more thing how could I add the height and width to control those things. I tried various combos but none seems to work.


On Friday, April 26, 2013 5:22:32 PM UTC+5:30, rushabh wrote:
Aditya,

webnotes.client.get_value is a server side function.

You will need the value (tool_type_image) in your current transaction using add_fetch

Then use an image tag like:

<script>"<img src='" + doc.tool_type_image + "' />"</script>

This should work...

best,
Rushabh




W: https://erpnext.com
T: @rushabh_mehta

On 26-Apr-2013, at 3:41 PM, Aditya Duggal <aditya...@gmail.com> wrote:

Hi,

I need to pull an image in a print format from a different doctype. I have tried using this 

<script>webnotes.client.get_value("Tool Type", doc.tool_type, "image")</script>

But this is not helping me out can you suggest a code hidden in the client side so that I could fetch a photo attached to a doctype.

On Friday, April 19, 2013 2:37:39 PM UTC+5:30, Addy wrote:
Hi Anand,

Thanks you very much for the NO COPY code it should solve a lot of problems for me. As for the file list I can definitely wait and I guess I would be letting it sleep till the time new release are made and as for the image placeholder I think Umair gave me a very simple solution of opening the attachment which I don't know why I did not think of and hence I guess the placeholder part is also done.

Once again thanks a lot for all the help you people have been offering.

--
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.

Anand Doshi

unread,
Apr 26, 2013, 10:47:20 AM4/26/13
to erpnext-dev...@googlegroups.com
Hi Aditya,

You can put that in the style attribute of img.

<script>"<img src='" + doc.tool_type_image + "' style='width: 200px; height: 100px' />"</script>

Thanks,
Anand.

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

To post to this group, send email to erpnext-dev...@googlegroups.com.

Aditya Duggal

unread,
Apr 27, 2013, 12:46:14 AM4/27/13
to erpnext-dev...@googlegroups.com
Thanks Anand

Anand.

Addy

unread,
May 1, 2013, 7:49:44 AM5/1/13
to erpnext-dev...@googlegroups.com
Hi,

I was wondering if it is possible to replace NULL or ZERO values in FLOAT with something else in a Query Report.

Basically currently my query is like this:

ifnull(`tabItem`.height_dia,"'") as "H/D:Float:60",

Now this runs good but I would want to replace the ZERO values as well with the same symbol but cannot seem to figure out the correct syntax.

I have tried this as well:

if(ifnull(`tabItem`.height_dia,"'")==0,"'", `tabItem`.height_dia) as "H/D:Float:60",

But it does not seem to be working. Is this kind of a thing even possible since with all the ZEROS the things don't look very elegant and are difficult to read in a report.

Rushabh Mehta

unread,
May 2, 2013, 4:53:21 AM5/2/13
to erpnext-dev...@googlegroups.com
Aditya,

Made an update so that null values are printed as empty strings instead of 0s. Will push it in sometime.

- Rushabh


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

To post to this group, send email to erpnext-dev...@googlegroups.com.

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



--



Twitter: @rushabh_mehta

Aditya Duggal

unread,
May 2, 2013, 4:58:17 AM5/2/13
to erpnext-dev...@googlegroups.com
Dear Rushabh,

Basically I was looking to replace the blank field with ' since filtering for blank fields is difficult and I would also like to replace the 0.000 values as well with the ' or any other small value since they look very bad and unreadable. Here is a screen shot of the report:

Inline image 1
image.png

Anand Doshi

unread,
May 2, 2013, 5:00:59 AM5/2/13
to erpnext-dev...@googlegroups.com
Hi Aditya,

Just use the if condition to set 0 values as null.

Thanks,
Anand.

On 02-May-2013, at 2:28 PM, Aditya Duggal <adi...@rigpl.com> wrote:

Dear Rushabh,

Basically I was looking to replace the blank field with ' since filtering for blank fields is difficult and I would also like to replace the 0.000 values as well with the ' or any other small value since they look very bad and unreadable. Here is a screen shot of the report:

<image.png>

--
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 post to this group, send email to erpnext-dev...@googlegroups.com.

Nabin Hait

unread,
May 3, 2013, 1:45:22 AM5/3/13
to erpnext-dev...@googlegroups.com
if(`tabItem`.height_dia==0,"'", ifnull(`tabItem`.height_dia,"'")) as "H/D:Float:60"

Aditya Duggal

unread,
May 3, 2013, 5:35:56 AM5/3/13
to erpnext-dev...@googlegroups.com
I am using this code but I am getting a syntax error:

if(`tabItem`.no_of_flutes==0,"'",ifnull(`tabItem`.no_of_flutes,"'")) as "Zn:Float:30",

Is there something that my code is missing from yours, I can't seem to find the error but it is showing a syntax error. The whole code is here.



On Friday, May 3, 2013 11:15:22 AM UTC+5:30, Nabin Hait wrote:
if(`tabItem`.height_dia==0,"'", ifnull(`tabItem`.height_dia,"'")) as "H/D:Float:60"
On 02-May-2013, at 2:30 PM, Anand Doshi wrote:

Hi Aditya,

Just use the if condition to set 0 values as null.

Thanks,
Anand.
On 02-May-2013, at 2:28 PM, Aditya Duggal <adi...@rigpl.com> wrote:

Dear Rushabh,

Basically I was looking to replace the blank field with ' since filtering for blank fields is difficult and I would also like to replace the 0.000 values as well with the ' or any other small value since they look very bad and unreadable. Here is a screen shot of the report:

<image.png>

--
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.

To post to this group, send email to erpnext-dev...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
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.

Anand Doshi

unread,
May 3, 2013, 5:42:14 AM5/3/13
to erpnext-dev...@googlegroups.com
Try this:

if(ifnull(`tabItem`.no_of_flutes, 0)=0, null, `tabItem`.no_of_flutes) as "Zn:Float:30"

Rushabh has done some changes in formatting of grid, such that it will show null values as blank. (You might need to update)

Thanks,
Anand. 

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

To post to this group, send email to erpnext-dev...@googlegroups.com.

Aditya Duggal

unread,
May 3, 2013, 6:07:53 AM5/3/13
to erpnext-dev...@googlegroups.com
Dear Anand,

The code works fine, but it does not solve my purpose. Basically I don't want blank fields in the report since I am not aware of searching for BLANK fields hence I wanted to replace all NULL and ZEROS with any character so that people could search for NULL fields as well and at the same time the report is not FILLED with data and hence a single digit to replace the NULL makes the report looks good and also makes the searching for the fields possible.

Aditya Duggal

unread,
May 3, 2013, 10:15:09 AM5/3/13
to erpnext-dev...@googlegroups.com
Hi Anand,

I am using this in my print format:

<script>"<img src='" + doc.dim_image_list + "' style='width: 500px; height: 250px'/>"</script>

Also I am getting this field from the server side scripting by the below code:

self.doc.dim_image_list = webnotes.conn.get_value("File Data", {"attached_to_doctype": "Tool Type", "attached_to_name": self.doc.tool_type}, "file_url")

But the problem is that if I change the image in the TOOL TYPE the effects would not reflect until I edit and save an item. Is there any way I could get the updated image on the print format of an item as soon as the image on the TOOL TYPE is CHANGED or do I have to do a UPDATE of the DB from the SYSTEM CONSOLE every time I change the image and if that is the only thing possible then should this code work on the backend:

webnotes.conn.sql("UPDATE `tabItem` SET dim_image_list = `tabFile Data`.file_url WHERE `tabFile Data`.attached_to_doctype = 'Tool Type' AND `tabFile Data`.attached_to_name = `tabItem`.tool_type")

But I guess this is wrong since I would need to join the tables and honestly the JOINS scare the hell out of me since I tried it once and you all were forced to throw my account out of erpnext (just joking).

Hence I request you to kindly let me know how to join the 2 tables or is there a better way to get the updated image automatically.
Anand.

Rushabh Mehta

unread,
May 4, 2013, 5:01:53 AM5/4/13
to erpnext-dev...@googlegroups.com
Aditya,

You can update explicitly using the update query in Server Custom Script of Tool Type. Joins are not bad if you are joining once or twice :)


best,
Rushabh




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

To post to this group, send email to erpnext-dev...@googlegroups.com.

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



--



Twitter: @rushabh_mehta

Aditya Duggal

unread,
Apr 24, 2014, 7:16:20 AM4/24/14
to erpnext-dev...@googlegroups.com
Hi,

I would like to know if there is a way to hide a field irrespective of the fields current state (hidden or unhidden). The current toggle.display command only lets us change the display state and you can never be sure whether the item is being displayed or not.

Is there a command on client side script that I can use to explicitly hide or make mandatory certain fields.

I have checked the client side scripting help page and could not find anything there :(
Anand.

Thanks rushabh,

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

To post to this group, send email to erpnext-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/BkXD_-W0XSkJ.

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

--
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+unsubscr...@googlegroups.com.

To post to this group, send email to erpnext-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/l5aLqqc7RxwJ.

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

--
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.
To post to this group, send email to erpnext-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/zmnrZm82ih8J.

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

Anand Doshi

unread,
Apr 24, 2014, 9:17:08 AM4/24/14
to Aditya Duggal, erpnext-dev...@googlegroups.com

Hi Aditya,

cur_frm.toggle_field(“fieldname”, false) will hide the field :)

Essentially it sets the hidden property of the field to true.


Thanks,
Anand Doshi.
--
Note:
 
If you are posting an issue,
1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---

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/8353f8d1-b835-4529-ab61-0d404c4228da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aditya Duggal

unread,
Apr 24, 2014, 9:52:27 AM4/24/14
to erpnext-dev...@googlegroups.com, Aditya Duggal
Perfect

Thanks alot.
Anand.

Thanks rushabh,

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

--
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.
To post to this group, send email to erpnext-dev...@googlegroups.com.
--
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.
To post to this group, send email to erpnext-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/zmnrZm82ih8J.

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



--



Twitter: @rushabh_mehta
--
Note:
 
If you are posting an issue,
1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
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.

Edney Oliveira

unread,
May 16, 2014, 9:46:26 PM5/16/14
to erpnext-dev...@googlegroups.com
Hi Aditya,

     I have the same problem, but the field that I want to hide is in a grid. Your example didn't work in this case. How can I hide the field in a grid?

Thanks!
Edney


Em quarta-feira, 27 de fevereiro de 2013 02h44min12s UTC-3, rushabh escreveu:
Aditya,

Check the first example:


You can also use this to set the "hidden" property of docfield (df).

best,
Rushabh


W: https://erpnext.com
T: @rushabh_mehta

On 25-Feb-2013, at 4:08 PM, Aditya Duggal <aditya...@gmail.com> wrote:

Hi,

I have some queries with regards to custom scripts:

  1. I am trying to make certain fields in the item master as "READ-ONLY" but after the creation of item codes. Since my item codes would be dependent on these fields and to maintain the integrity of the items I would like to lock these fields using the custom script. Kindly let me know how to achieve this by using custom reports.
  2. Is there a way to show certain fields on screen at the time of item creation since they are the ones according to which the item code is created, something on the lines of the item variant which is long pending but now I am trying to prepare one myself.



--
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.
To post to this group, send email to erpnext-dev...@googlegroups.com.

Rushabh Mehta

unread,
May 17, 2014, 6:02:00 AM5/17/14
to erpnext-dev...@googlegroups.com
Can you share your script via pastebin so we can check what you have done.



@rushabh_mehta

--
Note:
 
If you are posting an issue,
1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
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/8c76464b-73cb-41d3-83f2-c80210242daf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Edney Oliveira

unread,
May 18, 2014, 9:55:30 PM5/18/14
to erpnext-dev...@googlegroups.com
Hi Rushabh!

      This is the code snippet I made to try to hide the field. What do I need to work properly?


    cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query = function(doc,doctype,docname) {
       return "SELECT ..., default_warehouse,... FROM `tabItem` WHERE ...;
    };

    cur_frm.add_fetch('item_code', 'default_warehouse', 'item_kind');

    var hideField = cur_frm.fields_dict['quotation_details'].grid.get_field('item_kind').value=="Accommodation";

    // the field 'nights_number' is in a grid 'quotation_details', how can hide the field? The field is not present in a principal form.
    cur_frm.toggle_display("nights_number", hideField);   // doesn't work!

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

Rushabh Mehta

unread,
May 19, 2014, 1:17:40 AM5/19/14
to erpnext-dev...@googlegroups.com
Edney, this is very hard to read. Can you share via pastebin or gist.github.com



@rushabh_mehta

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/4c5bd6bc-63c7-4a21-9e50-1685e989facf%40googlegroups.com.

Edney Oliveira

unread,
May 23, 2014, 12:22:35 AM5/23/14
to erpnext-dev...@googlegroups.com
Hi Rushabh!

      This is my code: http://pastebin.com/ffA0W3jV

      When the field 'tipo_item' changes the scripts works fine, but when the form opens for editing the code is not executed and therefore the field "noites_hospedagem" is visible when it should be invisible. What do I need to modify to work correctly in this case?

Thanks,
Edney



@rushabh_mehta

Nabin Hait

unread,
May 23, 2014, 12:58:53 AM5/23/14
to erpnext-dev...@googlegroups.com

You should call the function `cur_frm.cscript.tipo_item` from  `cur_frm.cscript.custom_refresh`.

And that get_query statement should be declared outside tipo_item trigger function.

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/92c10c68-16ea-45c3-8f21-ec167b59ce01%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages