Quantcast
Channel: SNBlog – by Logicalis SMC
Viewing all articles
Browse latest Browse all 89

Help! My new number disappeared!

$
0
0

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

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

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

Choose “Insert and Stay” from the option list.
image007

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

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

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.

doInsertAndStay();
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
current.insert();
action.setRedirectURL(saveMe);
}

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 (hidden[at]hidden)


Viewing all articles
Browse latest Browse all 89

Trending Articles