Help! My new number disappeared!

General Add comments

Help! My new number disappeared (when using “Insert and Stay”)……

Recently a customer asked me for support on some strange behaviour of a number field. They had created a custom table with a field ‘u_number’.

Let’s reproduce this on a demo instance running HEAD (Dublin). Goto “Tables & Columns” and choose “Create Table”. Name the table “mycustomtable” and accept all ServiceNow filled fields based on our table name.

Add some records to the newly created “mycustomtable” table.

Choose one of the existing records and make use of the “Insert and Stay” functionality.
Open the record and change the value in the field u_number to a unique number.

Choose “Insert and Stay” from the option list.

After the “Insert and Stay” the u_number field is emptied and our assigned number has disappeared.

If you leave the newly inserted record then you return to the list. In the list is now a record with an empty u_number field.

Look for the 2 global actions called “Insert an Stay”.
In the script you will see that u_number is mentioned. The field number and u_number are emptied and made ready for a new number to be generated. But in our case we don’t make use of a counter and we want the flexibility of assigning our own numbers.

function doInsertAndStay() {
var saveMe = current;
if (typeof current.number != ‘undefined’ && current.number)
current.number = “”; // generate a new number
else if (typeof current.u_number != ‘undefined’ && current.u_number)
current.u_number = “”; // generate a new number

There are several ways you can work around this but what is important is that this is where your code has to be added in other to prevent the u_number field from being emptied.

Possible solutions:
– add code to check if there is a counter specified for the combination of table + field and skip the clearing of the u_number field when there is no counter specified
– check if the current table matches our mycustomtable and skip the clearing of the u_number field

I hope this blog article is helpful. If you have questions, please let me know via email or a response below!

Good luck!
Kind regards,
Richard Lurks (.img[at].img)

Leave a Reply