How to generate a unique code (it should work same like number field we have in RITM and TASK) using text field in request form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2017 10:58 PM
Hi All,
I'm trying to create a new field with unique value (for example like TAC12345) and the text field should auto generate the code whenever users submit a request (same as number field that we have now).
I tried with javascript:getNextObjNumberPadded(); it didn't work. Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2017 02:41 AM
Hi Sarasaamani,
Do following:
1. Create an Onsubmit script in the catalog item and do a GlideAjax call to insert new record in OCID table and return back the sys id of the generated record and fill in the variable with the new value;
Use below code to map the variable with the incident table record. You just have to replace the table with your OCID table.
Onsubmit client script :
function onSubmit() {
var requireCode = g_form.getValue('u_inc_req');
if(requireCode == 'Yes'){
var myAjax = new GlideAjax("crtOCIDcode");
myAjax.addParam('sysparm_name','genrateCode');
myAjax.addParam('sysparm_req','requireCode');
myAjax.getXMLWait();
var OCID = myAjax.getAnswer();
g_form.setValue('u_inc_number',OCID);
}
}
Script Include:
var crtOCIDcode = Class.create();
crtOCIDcode.prototype = Object.extendsObject(AbstractAjaxProcessor, {
genrateCode : function() {
var gr = new GlideRecord('incident'); // replace the table with the OCID table
gr.initialize();
gr.short_description = "test ravi" ; // fill with you own custom values
gr.insert();
return gr.sys_id ; // yey! got the sys id of the new record
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2017 12:46 AM
Hi Sarasa
The number maintenance work on the servicenow tables and to get those number you need to define the number system for that table where you want the auto generate number. Please see the below link how to setup the number system.
http://wiki.servicenow.com/index.php?title=Managing_Record_Numbering#gsc.tab=0
It looks like you are trying to use a number maintenance for a catalog item.Please confirm where you need the unique number on catalog item/Record producer or on the servicenow actual table.
If it is a servicenow table then setup number maintenance based on the above link.
If it is a catalog item then write a script to generate the unique number. The best way to setup the unique code is use the current datetime as unique number like "DDMMYYYYHHMMSS", This string will be always unique.
Regards,
Harsh