How to add a list of CI from Catalog variable to Affected CI related list?

gale3
Kilo Contributor

I have a list collector of CI (cmdb_ci) in my catalog. Upon submission I would like it to be added to the Affected CI related list on my RITM module. Do you have any idea how to do this? Thank you very much.

10 REPLIES 10

Kunal Varkhede
Tera Guru

Hi,

 

you can use OnSumbit() client script here first you get all the list collector value store it in array and then pass it to the script include. In script include you can glide the related list table and store in that and update it.

 

Thanks,

Kunal

Hi, do you have an example code? thank you very much.

Kunal Varkhede
Tera Guru

Hi,

 

You can try like below modified according to your requirement

OnSubmit() client script

 

function onSubmit()

{

var ga = new GlideAjax('scriptIncludeName');

ga.addParam('sysparm_name','functionName');

ga.addParam('sysparm_list_collector_value',g_form.getValue('list_collector_field_name'));

ga.getXMLAnswer(callback);

function callback(response)

{

var answer =response;

}

}

Script Include

 

scriptIncludeName: function()

{

var list_collector_data = this.getParameter('sysparm_list_collector_value');

var array = list_collector_data(',');

for(var i = 0;i<array.length;i++)

{

var gr = new GlideRecord('table Name');//related list table name

gr.fieldName = array[i];

//gr.fieldName +=array[i];

gr.update();

}//for loop close

}//function is close

 

I hope it will help you

Please Mark Correct/Helpful answer if it help you in any way.

Thanks,

Kunal.

Brad Bowman
Kilo Patron
Kilo Patron

Since you don't need to see this on the request form, it will be easiest and best to do it server side.  On your workflow that is running on this RITM, add a Run Script activity with a script something like this

var ciarr = [];
ciarr.push(current.variables.list_collector_variable_name.toString());
for(var i=1;i<ciarr.length; i++){
var rec = new GlideRecord('task_ci');
rec.initialize();
rec.task = current.sys_id;
rec.ci_item = ciarr[i];
rec.insert();
}

 

Kaleshwari1
Kilo Contributor

Hi All, 

I have a follow-up question on the above scenario, the list collector variable in displaying the values on RITM level from the script given by Brad, but we need the list collector values of CI on Catalog task as well. 

We tried running the above script before on the catalog task activity of workflow and tried to add the reference fields on Configure >> Related Lists or Form Layout

 

Any insights on this follow-up question will be much helpful, Please suggest. 

Regards,

Kaleshwari