- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 07:48 PM
I have a customised table u_audit which inserts the INC record number whenever the INC is updated.For this I have created a customised string field(u_number) which captures INC number and I have created a customised field (u_count) on the audit table and I want to insert the counter(1,2,3,4,5...) on basis of insertion of INC record. For examples: when INC record is updated for 1st time a record should be inserted in u_audit table which populates u_number as INC number and u_count should be 1 and so on. Please can you let me know how to achieve this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 05:13 AM
If my answers helped you to resolve your queries then please mark them as correct or helpful based on the impact.
Thanks and Remarks
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 12:48 AM
The script is not working for me. I have written on OnBefore insert/update BR to insert the record. The record is getting inserted however the count is still showing as zero and increment is not happening. Please can you help me with the script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 12:54 AM
Can you please share what you have done?
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 01:00 AM
Hi,
Try below code,
if(current.operation()=="insert"){
//Record insertion code here
}else if(current.operation()=="update"){
var grAudit=new GlideRecord("u_audit");
grAudit.addQuery("u_number",current.number);
grAudit.query();
if(grAudit.next()){
grAudit.u_count=grAudit.u_count+1;
grAudit.update();
}
}
As you have mentioned insertion is working so I am assuiming that you have record insertion code that you can paste in second line where I have commented the same.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 01:23 AM
I am not sure how this will be on update but I have tried the below script OnBefore insert/update on Incident table with condition state is OnHold which does not work. I want to just increase the counter.
var count=0;
var gr=new GlideRecord('u_audit');
gr.initialize();
gr.u_number=current.number;
gr.u_assignment_group=current.assignment_group.getDisplayValue();
gr.u_count=count++;
gr.insert();
Would like to display the record number for a particular INC number. Please can you help me with this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 01:30 AM
Hi,
you need to update it like below:
var count=0;
if(current.operation()=="insert"){
var gr=new GlideRecord('u_audit');
gr.initialize();
gr.u_number=current.number;
gr.u_assignment_group=current.assignment_group.getDisplayValue();
gr.u_count=count++;
gr.insert();
}else{
var gr=new GlideRecord('u_audit');
gr.addQuery('u_number',current.number);
gr.query();
if(gr.next()){
count = parseInt(gr.u_count,10);
gr.u_count=count++;
gr.update();
}
}
Thanks,
Anil Lande
Thanks
Anil Lande