Need to create a multiple record when the form submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 03:17 AM
Hi All,
I am working on one of the form in this form I am using multi row variable set, contains Product Model, Keyboard Language, Quantity and Serial Number.
When the form submitted these 5
4RW3GY3
3Q2XBY3
4962GY3
JQW3GY3
7QW3GY3 records will be created in the alm_hardware table.
I tried with the below script
var multiRowSet = [];
var array=[];
var ass;
var sub;
multiRowSet.push(abc);
multiRowSet = JSON.parse(multiRowSet);
workflow.scratchpad.assetlength= multiRowSet.length;
gs.log('start63:' + multiRowSet.length);
for (var i = 0; i < multiRowSet.length; i++) {
array.push(multiRowSet[i].serial_number_1);
ass = multiRowSet[i].serial_number_1;
sub = multiRowSet[i].model2;
gs.log("asssub " + i + multiRowSet[i].serial_number_1+"/"+multiRowSet[i].model2);
gs.log('asssub71:'+ass+ "-"+sub);
var gr1 = new GlideRecord('alm_hardware');
gr1.initialize();
//gr1.addQuery('serial_number',multiRowSet[i].serial_number_1);
// gr1.query();
// if(gr1.next()){
gr1.serial_number=ass;
gr1.install_status = "6";
gr1.stockroom=current.variables.stockroom;
gr1.acquisition_method=current.variables.acquisition_method;
gs.log("stoacq78:"+current.variables.stockroom +"-"+current.variables.acquisition_method);
gr1.model = sub;
gr1.insert();
}
This script is working fine when I give the single Serial number, like below
If I give the multiple serial number, then this script is not working.
Note : Tried without using multi row variable set, and it is working as expected.
var sto=current.variables.stock_reservation;
var serial_number =current.variables.ser_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='9';
//grHardware.substatus='Commissioned';
grHardware.model=current.variables.Model;
grHardware.stockroom=current.variables.stockroom;
// grHardware.location='AE - Dubai City';
}
I need to create a multiple records using multi row variable set( Insert the multiple serial number on the serial number field)
Here I need to create 10 records when form get submitted.
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-13-2023 01:04 AM - edited 10-13-2023 01:09 AM
I tried with the above script and it is working fine and in the same script I wanted to implement to the configuration item(cmdb_ci_computer) as well,
I tried with the below script, But its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 01:30 AM
Hi @vinuth v
In my understanding, You already have "Configuration Item" with that Serial number & you want to update its name & set it in "alm_hardware" record in "Configuration item" field.
Forgive me if I'm interpreting in wrong way....is my understanding correct...??
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates