Need to insert a new value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 03:10 AM
Hi All,
I am working on one the form in this form I have serial number field and it is multi line text field. What are all the data I am adding on the Serial Number field that record will be created in the alm_hardware table.
Adding the value in the serial number like this
I wanted to create a 7 separate record in the alm_hardware table.
I tried with the below script in the work flow
var hr= new GlideRecord('alm_hardware');
hr.initialize();
hr.serial_number =current.variables.serial_number;
hr.install_status='1';
hr.substatus='Commissioned';
hr.model='Dell Latitude 5480';
hr.stockroom='AE-Dubai-MediaCity-Stockroom';
hr.location='AE - Dubai City';
hr.insert();
For this script only one record is created line
Please any one provide me the input,
Thanks in advance,
Vinuth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 03:22 AM
Hi @vinuth v
Since the "Serial Number" variable has been entered on separate lines
To successfully insert records for each Serial Number, we'll need to split them out accordingly.
Give the below script a try!
var serial_number = current.variables.serial_number.toString();
var arrSerialNumber = serial_number.split('\n');
for (var i in arrSerialNumber){
insertHardwareBySerialNumber(arrSerialNumber[i]);
}
/**
* Create new Hardware by Serial Number
* @return {void}: insert new Hardware record
*/
function insertHardwareBySerialNumber(serial_number){
var grHardware = new GlideRecord('alm_hardware');
grHardware.addQuery('serial_number', serial_number);
grHardware.query();
if(grHardware.next()){
return; //return if serial number existed.
}
//insert new hardware
grHardware.initialize();
grHardware.serial_number = serial_number;
grHardware.install_status='1';
grHardware.substatus='Commissioned';
grHardware.model='Dell Latitude 5480';
grHardware.stockroom='AE-Dubai-MediaCity-Stockroom';
grHardware.location='AE - Dubai City';
grHardware.insert();
}
Let me know if it works for you!
Cheers,
Tai Vu