- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2017 04:32 AM
Hi All,
I am facing a strange issue , I have written request.update() in mentioned code , It creating a new record rather than updating the matching record.
I have enabled debug log and checked this is creating a new record where the new record's status value is updated with the code value.
(function executeRule(current, previous /*null when async*/) {
var news;
var open;
var dev;
var rft;
var hold;
var reject;
var nrp;
var deferred;
var closed;
var cancelled;
var task = new GlideRecord('u_defect');
task.addQuery('u_new_requirement.number',current.u_new_requirement.number);
task.query();
while(task.next()){
if(task.u_status == 11){
news = 11; //1 = Open
gs.addInfoMessage("new of loop");
}
else if (task.u_status == 01){
open = 1;//6 = onHold
}
else if (task.u_status == 02){
dev = 2; // 2 = Work in progress
}
else if(task.u_status ==03){
rft = 3;// 3 = Closed Complete
}
else if (task.u_status == 04){
hold = 4 ; // 4 = Cancelled
}else if (task.u_status == 12){
reject = 12;//6 = onHold
}
else if (task.u_status == 07){
nrp = 7; // 2 = Work in progress
}
else if (task.u_status == 06){
deferred = 6; // 2 = Work in progress
}
else if(task.u_status ==05){
closed = 5 ;// 3 = Closed Complete
}
else if (task.u_status == 13){
cancelled = 13 ; // 4 = Cancelled
}
gs.addInfoMessage("out of loop");
}
var request = new GlideRecord('u_user_requirement');
request.addQuery('number',current.u_new_requirement.number);
request.query();
if(request.hasNext())
{
if(open ==1||news==11||dev == 2||hold == 4){
request.u_status =14;//Defect
}
else if(rft == 2||reject == 12||nrp == 7||deferred == 6||closed == 5||cancelled == 13){
request.u_status =07;//ready for testing
}
gs.addInfoMessage(request.u_status);
gs.addInfoMessage(request);
request.update();
}
})(current, previous);
Can any one tell what would be the reason for this.
I have written after insert and update BR on u_defect table, I need to update the data in u_user_requirement table.
Developer CommunityService Managementctomasi
Thanks,
Nithin.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2017 04:41 AM
Change your request.hasNext() to request.next().
hasNext() does not actually retrieve the record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2017 04:41 AM
Change your request.hasNext() to request.next().
hasNext() does not actually retrieve the record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2017 04:51 AM
Thanks Chuck . I missed basic logic , Never noticed that.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2019 06:04 AM
Ha. I had while(gr.next());{
The semi-colon was preventing the next record being found AND causing a duplicate creation rather than an update.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2017 04:42 AM
Hi Nithin,
At line number 68 can you replace hasNext() with next() and try once