Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

Set record counter

tanz
Tera Expert

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.

 

1 ACCEPTED SOLUTION

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

View solution in original post

30 REPLIES 30

Still the same issue. Its showing as NaN

Can you please share complete script ?

 

(function executeRule(current, previous /*null when async*/) {

// Add your code here
//var count=0;


var grAudit=new GlideRecord("u_audit");
grAudit.orderByDesc("sys_created_on");
grAudit.addQuery("u_number",current.number);
grAudit.query();
if(grAudit.next()){
var count=parseInt(grAudit.getValue("u_count"))+1;
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=count;
grAudit.insert();
}
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();
}

})(current, previous);

Please uncomment the 2nd line for var count=0;

(function executeRule(current, previous /*null when async*/) {

var count=0;

var grAudit=new GlideRecord("u_audit");
grAudit.orderByDesc("sys_created_on");
grAudit.addQuery("u_number",current.number);
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();
}

})(current, previous);

 

Above is corrected script.

 

Thanks,
Anil Lande

I am not sure but I am still getting NaN