- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 10:50 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 02:30 PM
For posterity, here is the RP that works, some of the variables needed to be declared as strings:
var modelCategory = '81feb9c137101000deeabfc8bcbe5dc4'; // Computer
var model = String(producer.mtm);
var installStatus = '6'; // In Stock
var stockroom = String(producer.stockroom);
var serialNums = String(producer.serial_number);
var serialArray = serialNums.split(",");
for (var i = 0; i < serialArray.length; i++) {
var hw = new GlideRecord('alm_hardware');
hw.initialize();
hw.setValue("model_category", modelCategory);
hw.setValue("model", model);
hw.setValue("serial_number", serialArray[i]);
hw.setValue("install_status", "6");
hw.setValue("stockroom", stockroom);
hw.insert();
}
current.setAbortAction(true);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 11:38 AM
Hi, I think that you would want to run your ajax call\check as an onChange() client script so that anytime the serial number variable is updated, the content is validated, I would also add a hidden yes/no variable that is populated by this script and use this field to prevent submission with an on submit script.
For your other issue, what are the results of your debugging
Have you debugged\logged the content and typeof 'serialString' and 'serialArray' to confirm that serialArray is an array and that it's content is correct and length are as expected? - This would impact the record(s) created by your loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 11:36 AM
For the verification I do indeed have an onChange script, I just didn't include it in my post because that part is working. Thanks for the yes/no variable suggestion, I'll keep that in mind when I fine-tune.
For the RP script (onSubmit script deactivated), when I log the value for each of my variables (before the for loop) they all come back as undefined. However, when I add a breakpoint on the line after the variables are set, each one is valued/set as expected. The for loop executes the expected number of times but alm_harward is not populating as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 02:30 PM
For posterity, here is the RP that works, some of the variables needed to be declared as strings:
var modelCategory = '81feb9c137101000deeabfc8bcbe5dc4'; // Computer
var model = String(producer.mtm);
var installStatus = '6'; // In Stock
var stockroom = String(producer.stockroom);
var serialNums = String(producer.serial_number);
var serialArray = serialNums.split(",");
for (var i = 0; i < serialArray.length; i++) {
var hw = new GlideRecord('alm_hardware');
hw.initialize();
hw.setValue("model_category", modelCategory);
hw.setValue("model", model);
hw.setValue("serial_number", serialArray[i]);
hw.setValue("install_status", "6");
hw.setValue("stockroom", stockroom);
hw.insert();
}
current.setAbortAction(true);