Whats wrong with below script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2024 09:48 AM
Hello All,
I am trying to set few fields on incident form using a transform map however i dont see values coming in.
What is wrong in below script? can someone advise here?
For CI mapping, please note that class should contain server because in cmdb we have different ci's with hostnames extracted in different classes like virtual instances and all.
-------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2024 10:11 AM
(function runTransformScript(source, map, log, target /*undefined onStart*/) {
var str = source.tags.toString() || '';
var ci = '';
var suppG = '';
var arr = str.split(',');
for (var i = 0; i < arr.length; i++) {
if (arr[i].indexOf('Hostname:') === 0) {
ci = arr[i].split(':')[1].trim();
}
if (arr[i].indexOf('Product Team') === 0) {
suppG = arr[i].split(':')[1].trim();
}
}
var ciGr = new GlideRecord('cmdb_ci');
ciGr.addQuery('name', ci);
ciGr.addQuery('class', 'CONTAINS', 'server');
ciGr.query();
if (!ciGr.next()) {
ci = 'CI Not Found - Hardware';
}
var grpGR = new GlideRecord('sys_user_group');
grpGR.addQuery('name', suppG);
grpGR.query();
if (!grpGR.next()) {
var cmdbGr = new GlideRecord('cmdb_ci');
cmdbGr.addQuery('name', ci);
cmdbGr.query();
if (cmdbGr.next()) {
suppG = cmdbGr.support_group;
}
}
target.cmdb_ci = ci;
target.assignment_group = suppG;
target.u_resolution_ci = ci;
})(source, map, log, target);
Can you try this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2024 10:25 AM
Hello Dvelloriy,
Would you please check if below str is returning value. I don't see field 'source.tags in cmdb_ci, instead I see
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2024 11:37 AM - edited ‎10-22-2024 11:39 AM
Hi @dvelloriy ,
Try changing below lines and see if it works for you
ciGr.addEncodedQuery('sys_class_nameLIKEserver');
suppG = cmdbGr.support_group + '';
cmdb_ci is reference field so it will expect sys_id not string.
target.cmdb_ci = ciGr.sys_id;
target.u_resolution_ci = ciGr.sys_id;
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
