Item Master Script

Hello all,


I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can’t find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/brbo-mKnM94J.

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

 

 

Hi Mark,

Create a Custom Field of type Select and label "Naming Series" for Item doctype. Specify possible Naming Series options in the Options field, separated by newlines. Also, mark it Mandatory.

The next part is a trick.
Via the browser's address bar, go to yourdomain/app.html#Form/Property Setter/New Property Setter 1

Save a property setter with the following values, without the double quotes:
DocType or Field = "DocType"
DocType = "Item"
Property = "autoname"
Property Type = "Data"
Set Value = "naming_series:"

Go to Tools (last icon on the top bar) > Clear Cache & Refresh.

Try saving a new Item. It should take the correct series.

Thanks,
Anand.

On 24-Apr-2013, at 2:02 PM, MarkW <wa...@googlemail.com> wrote:

Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can't find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/brbo-mKnM94J.

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

To post to this group, send email to er...@googlegroups.com.

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

 

 

Hello Anand,


Thanks for your reply. I’m sure that would work, but I would perfer the user be able to overwrite the automatically generated value. So for that reason I don’t want this action to happen on save, but in reaction to a button press. I don’t think your solution is amenable to this as it automatically sets it on save, not under script control.

If I could extract a list of existing IDs I think this would be the most generic solution, but I’m unsure how to extract this from the database.

Regards,

MarkW

On Wednesday, April 24, 2013 9:32:11 AM UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can’t find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/N4qLCDGHoX8J.

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

 

 

Mark,

Here is what you can do


best,
Rushabh


On Wed, Apr 24, 2013 at 3:47 PM, MarkW <wa...@googlemail.com> wrote:
Hello Anand,

Thanks for your reply. I'm sure that would work, but I would perfer the user be able to overwrite the automatically generated value. So for that reason I don't want this action to happen on save, but in reaction to a button press. I don't think your solution is amenable to this as it automatically sets it on save, not under script control.

If I could extract a list of existing IDs I think this would be the most generic solution, but I'm unsure how to extract this from the database.

Regards,

MarkW


On Wednesday, April 24, 2013 9:32:11 AM UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can't find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er…@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/N4qLCDGHoX8J.


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





--



Twitter: @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-forum+un...@googlegroups.com.

To post to this group, send email to er...@googlegroups.com.

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

 

 

Thanks Rushabh,


That looks almost what I need. I am running this on a hosted system though, so I need to do this with a client side script. I think your code snippet is for a server side script? I’m not really familiar enough with this to know how to translate that to the client side. Is that possible?

Regards,

MarkW

On Wednesday, April 24, 2013 9:32:11 AM UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can’t find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/EAwdtjM95KAJ.

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

 

 

Mark,

Its a client script, you can put it in the trigger function of your custom field to select the item prefix - see the updated snippet


The hack is to use the report builder method to get the last id.

best,
Rushabh


On Wed, Apr 24, 2013 at 8:30 PM, MarkW <wa...@googlemail.com> wrote:
Thanks Rushabh,

That looks almost what I need. I am running this on a hosted system though, so I need to do this with a client side script. I think your code snippet is for a server side script? I'm not really familiar enough with this to know how to translate that to the client side. Is that possible?

Regards,

MarkW

On Wednesday, April 24, 2013 9:32:11 AM UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can't find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er…@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/EAwdtjM95KAJ.


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





--



Twitter: @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-forum+un...@googlegroups.com.

To post to this group, send email to er...@googlegroups.com.

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

 

 

Again, many thanks.


I’m still struggling I’m afraid. This is how I have implemented your code : My code for script - next_id is a button defined on the form. I modified your code to return any records (like '%') and to simply assign this value to the new value without any manipulation. I still get a blank though. Any further ideas? · GitHub

Can you see any issues with this as I just get a blank.

MarkW

On Wednesday, April 24, 2013 9:32:11 AM UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can’t find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/xua8DLX4WfUJ.

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

 

 

Hi Mark,

What are you getting in the callback of wn.call method? Are you getting any value? or are you facing an issue with setting the value of the field?

Thanks
Anand.

On 24-Apr-2013, at 9:47 PM, MarkW <wa...@googlemail.com> wrote:

Again, many thanks.

I'm still struggling I'm afraid. This is how I have implemented your code : https://gist.github.com/GreyMark7650/5453382

Can you see any issues with this as I just get a blank.

MarkW

On Wednesday, April 24, 2013 9:32:11 AM UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can't find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/xua8DLX4WfUJ.

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

To post to this group, send email to er...@googlegroups.com.

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

 

 

Mark,

Can you check what response you are getting on the call by keeping your javascript console window open?

best,
Rushabh


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

On 24-Apr-2013, at 9:47 PM, MarkW <wa...@googlemail.com> wrote:

Again, many thanks.

I'm still struggling I'm afraid. This is how I have implemented your code : https://gist.github.com/GreyMark7650/5453382

Can you see any issues with this as I just get a blank.

MarkW

On Wednesday, April 24, 2013 9:32:11 AM UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can't find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/xua8DLX4WfUJ.

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

To post to this group, send email to er...@googlegroups.com.

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

 

 

Thanks to everyone who responded. Your last questions pointed me in the right direction. The routine was returning the correct value and populating the field, but the display wasn’t updating. I don’t think the line of code following the callback function was being executed. When I put the “refresh_field” call inside the callback “cur_frm.refresh_field(“item_code”);” it worked as expected.


Regards,

MarkW

On Wednesday, 24 April 2013 09:32:11 UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can’t find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/oNxhdbyWuWQJ.

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

 

 

OK not quite out of the woods yet. I thought I had got it for a while. The code provided works fine now, but I can’t work out how to change the pattern for LIKE to a variable so that I can return a result from the appropriate group. Since I couldn’t find this out I aslo tried to put the call & callback inside the switch statement , but that also returns syntax errors. Any ideas?

On Wednesday, 24 April 2013 09:32:11 UTC+1, MarkW wrote:

Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can’t find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/c6CFP7CyylQJ.

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

 

 

Mark,

"%" is a wild-card. if you want a series with prefix ABC, search for like "ABC%"

if you use cur_frm.set_value - it should also refresh

best,
Rushabh


On Thu, Apr 25, 2013 at 2:05 PM, MarkW <wa...@googlemail.com> wrote:
OK not quite out of the woods yet. I thought I had got it for a while. The code provided works fine now, but I can't work out how to change the pattern for LIKE to a variable so that I can return a result from the appropriate group. Since I couldn't find this out I aslo tried to put the call & callback inside the switch statement , but that also returns syntax errors. Any ideas?


On Wednesday, 24 April 2013 09:32:11 UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can't find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er…@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/c6CFP7CyylQJ.


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





--



Twitter: @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-forum+un...@googlegroups.com.

To post to this group, send email to er...@googlegroups.com.

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

 

 

Hi Rushabh,


Yes, I got that, but the prefix needs to depend on which group the Item is in. I have this from the item_group field, but the pattern that LIKE is matching needs to be a variable to accommodate this.

The not updating was my fault, there was another code line later that was reverting the value back.

Regards,

MarkW

On Wednesday, 24 April 2013 09:32:11 UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can’t find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/CuiVfqAkCTkJ.

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

 

 

Mark,

The sql query is a string -- see my updated gist

https://gist.github.com/rmehta/5452216

best,
Rushabh


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

On 25-Apr-2013, at 3:39 PM, MarkW <wa...@googlemail.com> wrote:

Hi Rushabh,

Yes, I got that, but the prefix needs to depend on which group the Item is in. I have this from the item_group field, but the pattern that LIKE is matching needs to be a variable to accommodate this.

The not updating was my fault, there was another code line later that was reverting the value back.

Regards,

MarkW

On Wednesday, 24 April 2013 09:32:11 UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can't find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/CuiVfqAkCTkJ.

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

To post to this group, send email to er...@googlegroups.com.

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

 

 

OK again thanks to everyone. With the help of this group and a colleague I have come up with this script:


https://gist.github.com/GreyMark7650/5459251

It assumes that the item group has already been selected and that the group name has a prefix of the form"XXX-". The script extracts this prefix and uses it to search for the item with this prefix that has the highest suffix (XXX-YYYYYY). It Increments the suffix by one and populates the item code box with this.


On Wednesday, 24 April 2013 09:32:11 UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can’t find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/51qfioqL0hQJ.

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

 

 

A script for erpnext to generate the next item ID in the specified product group. · GitHub


I think this link works

On Wednesday, 24 April 2013 09:32:11 UTC+1, MarkW wrote:
Hello all,

I am trying to create a script that populates the Item ID, when creating a new item, with the next available number in a sequence. I have a script attached to a button on the item master page that runs correctly and extracts the item group, forms a new ID and updates the ID field.

What I need now is some information on how to get the next sequence number. I can think of two ways of doing this (1) iterate through all of the already created items to find the highest number or (2) use a naming series and have it give me the next number in the series.

I think #2 would be preferable, but I can’t find any information on how to go about doing either. Can any of you experts help with this information?

Regards,

MarkW



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

To post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/G_irS3o3rJ0J.

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