- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 04:17 PM
Hi, I've made a record producer that contains a list collector for records from the Affected CI's (task_ci) table. I want to create an incident through the record producer that populates my related list with the selected task_ci records that was chosen from the slush bucket. My code isn't working though, I can't figure out why. This is my code:
var myvar = current.getValue('slush_bucket');
var ci = myvar.split(",");
for (var i=0; i < ci.length; i++) {
var tci = new GlideRecord('task_ci');
tci.initialize();
tci.task = current.sys_id;
tci.ci_item = producer.slush_bucket;
tci[i];
tci.insert();
}
Any help will be appreciated, thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 10:45 PM
I misread your original post. Your variable should be referencing the cmdb_ci table rather than the task_ci table. This is because the task_ci.ci_item field is a reference to cmdb_ci. It is best to ensure the slushbucket value is a string too before using the split method. If that still fails, I'd also add some logging to the script so you can see how far it is working and what values are being used.
- var myvar = producer.slush_bucket;
- gs.log("Record Producer Slushbucket value = " + myvar);
- var ci = myvar.toString().split(",");
- var tci = new GlideRecord('task_ci');
- for (var i=0; i < ci.length; i++) {
- gs.log("Record Producer Slushbucket item " + i + " = " + ci[i] + ". Incident ID = " + current.sys_id);
- tci.newRecord();
- tci.task = current.sys_id;
- tci.ci_item = ci[i];
- tci.insert();
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 05:04 PM
Try this:
- var myvar = producer.slush_bucket;
- var ci = myvar.split(",");
- var tci = new GlideRecord('task_ci');
- for (var i=0; i < ci.length; i++) {
- tci.newRecord();
- tci.task = current.sys_id;
- tci.ci_item = ci[i];
- // tci[i];
- tci.insert();
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 05:58 PM
The code is a lot cleaner, but selected records still do not show in the related list section for task_ci
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 10:45 PM
I misread your original post. Your variable should be referencing the cmdb_ci table rather than the task_ci table. This is because the task_ci.ci_item field is a reference to cmdb_ci. It is best to ensure the slushbucket value is a string too before using the split method. If that still fails, I'd also add some logging to the script so you can see how far it is working and what values are being used.
- var myvar = producer.slush_bucket;
- gs.log("Record Producer Slushbucket value = " + myvar);
- var ci = myvar.toString().split(",");
- var tci = new GlideRecord('task_ci');
- for (var i=0; i < ci.length; i++) {
- gs.log("Record Producer Slushbucket item " + i + " = " + ci[i] + ". Incident ID = " + current.sys_id);
- tci.newRecord();
- tci.task = current.sys_id;
- tci.ci_item = ci[i];
- tci.insert();
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2015 12:44 PM
Thanks! I fixed my variable and now the code works.