I want to update records in expedite table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 10:45 PM
Hi All,
please help me with below requirement
I have one expendably table in witch I have one field called serial no. with integer type, this field's value should increase when new record is created so for that I have written 1 BR and it is working fine. but now I want that previously added record's value should also sequence wise display in that record. please let me know how to resolved this.
I thinks I need write fix script for that but let me know the script. below After Insert BR I have written.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 11:49 PM
1. First you need to update existing data using a fix script:
// Initialize a starting serial number (1 in this case)
var serNum = 1;
// Create a GlideRecord object for the target table
var ab = new GlideRecord('x_upl2_mx_digitize_sample_and_analysis');
// Order the records by creation date for efficient iteration
ab.orderBy('sys_created_on');
// Execute the query to retrieve all records
ab.query();
// Loop through each record
while (ab.next()) {
// Update the record's "u_serial_number" field with the current serial number
ab.u_serial_number = serNum;
// Update the record in the database
ab.update();
// Increment the serial number for the next record
serNum++;
}
// Retrieve the latest record (ordered by descending creation date)
var ab = new GlideRecord('x_upl2_mx_digitize_sample_and_analysis');
ab.orderByDesc('sys_created_on');
ab.setLimit(1); // Only fetch the most recent record
ab.query();
// Check if a record was found
if (ab.next()) {
// Extract the latest serial number and convert it to an integer
var latestNum = parseInt(ab.u_serial_number, 10);
// Set the current record's "u_serial_number" to the latest number + 1
current.u_serial_number = latestNum++;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2023 01:26 AM
Hi Gurpreet,
I have written fixscript given by you but it's not working properly. my expendably table is under x_upl2_mx_digitize_experiment table. so I am not getting serial no. in proper way so is it possible to autopupulate the seriol no. basis on