- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2018 08:11 PM
Hi,
I ma facing a challenge at the moment and would like some guidance.
scenario
i am querying the server table, the query returns the last server name, then i am increasing the value plus one then passing it to as a field value.
all good here.
if a second user submits a request he/she will get the same value on query then the request will fail.
My script include is doing the following:
I am passing a variable i.e; 'apps'
var essUniqueserverName = Class.create();
essUniqueserverName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
test: function(){
var pref=this.getParameter('sysparm_type_env');
gs.log(pref);
//return pref;
var indexingRecord = new GlideRecord('tableName');
indexingRecord.addQuery('name','STARTSWITH', pref);
indexingRecord.orderByDesc('name');
//indexingRecord.chooseWindow(1,1);
indexingRecord.query();
var rCount=indexingRecord.getRowCount();
var lastValue = '';
// if count = 0 the return value+ 0001
if (rCount == 0){
return pref + '0001'; //
}
else if (indexingRecord.next()){
lastValue= indexingRecord.name;
//gs.info(indexingRecord.name);
//return indexingRecord.name;
}
var numb= lastValue.substring(4,8); //get the last 4 digits
var numt=Number(numb)+1; // increment by 1
if (numt<10 ){
return pref+'000'+numt;
} else if(numt<100){
return pref+'00'+numt;
} else if (numt<1000) {
return pref+'0'+numt;
} else {
return pref+numt;// return value
}
},
type: 'essUniqueserverName'
});
Now the challenge is, if a second user submits a request this script run and get the same value. so the first request will success and the second will fail.
Any ideas on how i can prevent this?
The models is this
- query table for the last server name
- get servername increment by one
- pass the server name to external app.
- server get build in vcenter then pulled into the server table via api
Solved! Go to Solution.
- Labels:
-
Orchestration

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2018 08:19 PM
HI Henry,
This will always pull last server name right.
So this will always fetch the same name whenever you will query it.
You want same name always and then add count to it and then send to Venter?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2018 08:19 PM
HI Henry,
This will always pull last server name right.
So this will always fetch the same name whenever you will query it.
You want same name always and then add count to it and then send to Venter?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2018 08:39 PM
yes, this gets the last server name.
then the value gets passed to other app that in turns creates the Vm in vcenter, then the name get pull into service now... bit of a round trip but that is how it is at the moment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2018 08:42 PM
My issue is that if 2 people are submitting a request both will get the same number

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2018 08:47 PM
HI,
So say if two request gets submitted at the same time then you are getting an error?
Thanks