"Insert and Stay" not incrementing ticket #

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2011 07:19 AM
I created a new table for the manual entry of records. I also created a new system number and prefix to go along with the new table. When "Insert and Stay" is used as records are entered, a new record is created but with the same number as the original. How do I get my number to increment? The global button was there by default, and I also tried to create a new one specific to my table with no luck.
Thanks for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2011 07:28 AM
There may be an easier way, but you can create a "before insert" business rule on your table. In it, do a GlideRecord query for any existing records with the same number. Something like the following:
var duplicateCheck = new GlideRecord('u_your_table');
duplicateCheck.addQuery("number", current.number);
duplicateCheck.setWorkflow(false); // no need to run query business rules
duplicateCheck.setLimit(1); // no need to find more than one
duplicateCheck.query();
if (duplicateCheck.hasNext())
current.number = getNextObjNumberPadded();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2011 12:18 PM
This alllmooostt works. The only issue I see is that if I click "New" and I get 00001, when I say submit, I actually create 00002.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2011 05:29 AM
It looks like I need a condition to make this run only on a "Insert and Stay". It runs on submit right now, which causes the issue I mentioned before.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2013 09:17 AM
This is an old post, but I encountered the same issue and thought I would provide an answer.
The issue is in the UI Actions Insert and Insert and Stay. They reference the current.number field. Since there is no current.number field, you need to add ORs so that it looks at the current.u_number field. Here is what I changed the code in each to. Make sure you are editing the GLOBAL UI Actions (or insert a copy of the GLOBAL UI Actions and restrict them to your table. If you insert your own copy, you would likely need to modify the condition on the GLOBAL ones to exclude your custom table).
Insert
if ((typeof current.number != 'undefined' || typeof current.u_number != 'undefined') && (current.number || current.u_number)) {
current.number = ""; // generate a new number
current.u_number ='';
}
answer = current.insert();
Insert and Stay
doInsertAndStay();
function doInsertAndStay() {
var saveMe = current;
if ((typeof current.number != 'undefined' || typeof current.u_number != 'undefined') && (current.number || current.u_number)) {
current.number = ""; // generate a new number
current.u_number = "";
}
current.insert();
action.setRedirectURL(saveMe);
}