- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 12:35 PM
I have an excel sheet that has the ram in GB and I need it covered to MB on the computer cmdb_ci_computer table. The title on the excel is "DEVICE_MEMORY" and the values show as "10GB". I tried the script below but no luck, any advice?
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var deviceMemoryInt = parseInt(source.u_device_memory, 10);
if (!isNaN(deviceMemoryInt)) {
target.ram = deviceMemoryInt * 1024;
}
})(source, map, log, target);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 08:56 AM
Do you have the ram field on your field map? If so that maybe whats causing the issue with your script.
It would probably be easier to use a field mapping script. So add a field mapping and check the "Use source script" and use that script to do the calculation and then just return the value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 01:12 PM
When are you running the script? OnBefore, OnAfter or something else?
Have you tried using getValue and setValue?
var deviceMemoryInt = parseInt(source.getValue("u_device_memory"), 10);
if (!isNaN(deviceMemoryInt)) {
target.setValue("ram", deviceMemoryInt * 1024);
}
Also have you verified all of the field names to make sure they are correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 02:52 PM
Ive tried "onStart" and "onComplete" and neither worked for me. As far as the field names go, I know the target field is "ram" and the source filed on the spreadsheet is "DEVICE_MEMEORY" but on the filed map it shows it as "u_device_memory". I Tried what you suggest with "onStart" and "onBefore" but no dice with either. Any other suggestions?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2024 02:56 PM
You need to use either an OnBefore script or you need to use a field mapping script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 07:13 AM