- 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 04:42 AM
No if assignment group changes then it will not start from new, it will increment count from existing records.
Try below, it will work,
var count=0;
var grAudit=new GlideRecord("u_audit");
grAudit.orderByDesc("sys_created_on");
grAudit.addQuery("u_number",current.number);
grAudit.addQuery("u_assignment_group",current.assignment_group.getDisplayValue());
grAudit.query();
if(grAudit.next()){
var count=parseInt(grAudit.getValue("u_count"),10)+1; // always use 2nd parameter in parseInt
grAudit.u_assignment_group=current.assignment_group.getDisplayValue();
//grAudit.u_follow_up_date_and_time=current.sys_updated_on;
grAudit.u_count=count;
grAudit.update();
}
else{
var grAudit=new GlideRecord('u_audit');
grAudit.initialize();
grAudit.u_number=current.number;
grAudit.u_assignment_group=current.assignment_group.getDisplayValue();
//grAudit.u_follow_up_date_and_time=current.sys_updated_on;
grAudit.u_count=0;
grAudit.insert();
}
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 05:03 AM
Thankyou Again!!
- 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-02-2022 09:44 PM
Hi,
If the purpose here is to just get the count on how many times the ticket was updated, then you do not need a custom solution here.
There is an OOB way available as shown below:
1) There is a Field named as "Updates" which is an OOB field which already tracks on how many times an update was made to the record as shown below:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 12:49 AM
I want the update to happen only when state is OnHold. This field shows all updates