Adding CI's to related list from Record Producer

rsenecaljr
Kilo Guru

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.

1 ACCEPTED SOLUTION

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.



  1. var myvar = producer.slush_bucket;
  2. gs.log("Record Producer Slushbucket value = " + myvar);
  3. var ci = myvar.toString().split(",");
  4. var tci = new GlideRecord('task_ci');
  5. for (var i=0; i < ci.length; i++) {
  6.   gs.log("Record Producer Slushbucket item " + i + " = " + ci[i] + ". Incident ID = " + current.sys_id);
  7.   tci.newRecord();
  8.   tci.task = current.sys_id;
  9.   tci.ci_item = ci[i];
  10.   tci.insert();
  11. }

View solution in original post

4 REPLIES 4

Anthony_vickery
Tera Expert

Try this:


  1. var myvar = producer.slush_bucket;  
  2. var ci = myvar.split(",");
  3. var tci = new GlideRecord('task_ci');
  4. for (var i=0; i < ci.length; i++) {  
  5.   tci.newRecord();  
  6.   tci.task = current.sys_id;  
  7.   tci.ci_item = ci[i];  
  8. //   tci[i];  
  9.   tci.insert();  
  10. }

The code is a lot cleaner, but selected records still do not show in the related list section for task_ci


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.



  1. var myvar = producer.slush_bucket;
  2. gs.log("Record Producer Slushbucket value = " + myvar);
  3. var ci = myvar.toString().split(",");
  4. var tci = new GlideRecord('task_ci');
  5. for (var i=0; i < ci.length; i++) {
  6.   gs.log("Record Producer Slushbucket item " + i + " = " + ci[i] + ". Incident ID = " + current.sys_id);
  7.   tci.newRecord();
  8.   tci.task = current.sys_id;
  9.   tci.ci_item = ci[i];
  10.   tci.insert();
  11. }

Thanks! I fixed my variable and now the code works.