Need to update the related list on a change request form FROM catalog item list collector

Hervi
Tera Contributor

Hi Community,

 

I am trying to update related list of change request form. Suppose there is a related list A - i want to add multiple records to it from my catalog item. How can i achieve this? 

I am writing a catalog client script. I am storing the selected values of my list collector but after that i dont know how to copy those fields under  one of the related list on my change_request form.

My catalog item also has a field of change number. so only for the selected change these selected choices will be pasted in the related tab of change

 

@Prateek kumar  @Govind Kumar @Mohit Yadav @rohantyagi @vinothkumar @Adam Stout @gyedwab 

@Anil Lande @Ankur Bawiskar 

Kindly guide.

 

 

 

 

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    var collectorName = 'parent';
    var myListCollector = g_list.get(collectorName);
	var selectedValues = myListCollector.selectedValues();

   //Type appropriate comment here, and begin script below
   
}

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi @Hervi 

You can give the below script a try.

If you're using a Catalog item with some specific workflow, you can put it into the Script activity in your workflow. So after submission it will generate record to the Task Relationship table.

 

var changeSysID = current.variables.change_request_number.toString();
var parents = current.variables.parent.toString().split(',');
for (var i in parents){
    var gr = new GlideRecord('task_rel_task');
    gr.addQuery('child', changeSysID);
    gr.addQuery('parent', parents[i]);
    gr.addQuery('type', '<your_type_sys_id>'); //Store in the Task Relationship Type [task_rel_type] table
    gr.query();
    if(gr.hasNext()){
        continue;
    }
    gr.initialize();
    gr.setValue('child', changeSysID);
    gr.setValue('parent', parents[i]);
    gr.setValue('type', '<your_type_sys_id>');
    gr.insert();
}

 

 

Cheers,

Tai Vu

View solution in original post

6 REPLIES 6

Tai Vu
Kilo Patron
Kilo Patron

Hi @Hervi 

If I grasp it correctly, we have a form, and upon submission, we intend to insert the chosen data into a designated table. This way, these new records can be showcased in the related list of the change request form.

Could you share a screenshot of the form and the related list where you want to incorporate the data?

 

Cheers,

Tai Vu

Hervi
Tera Contributor

@Ankur Bawiskar Can you check this script - 

 

 

var answer = [];
var change = current.variables.change_request_number;
var listvalues = current.variables.parent.toString();
var listArr = listvalues.split(',');
for (var i = 0; i < listArr.length; i++) {
   var relatedListGR = new GlideRecord('task_rel_task');
   relatedListGR.addQuery('child', change);
   relatedListGR.query();
   while (relatedListGR.next()) {
      answer.push(relatedListGR.parent.getDisplayValue().toString());
relatedListGR.setValue('short_description', 'hi');
relatedListGR.setValue('priority', 3);
   }
}
gs.info('Answer array is: ' + answer);

 

 

its showing me error as parent and child is undefined. My list collector field is parent and i am trying to push the selected values to reference field named parent on task_rel_task table. please guide. 

Hi @Hervi 

You can give the below script a try.

If you're using a Catalog item with some specific workflow, you can put it into the Script activity in your workflow. So after submission it will generate record to the Task Relationship table.

 

var changeSysID = current.variables.change_request_number.toString();
var parents = current.variables.parent.toString().split(',');
for (var i in parents){
    var gr = new GlideRecord('task_rel_task');
    gr.addQuery('child', changeSysID);
    gr.addQuery('parent', parents[i]);
    gr.addQuery('type', '<your_type_sys_id>'); //Store in the Task Relationship Type [task_rel_type] table
    gr.query();
    if(gr.hasNext()){
        continue;
    }
    gr.initialize();
    gr.setValue('child', changeSysID);
    gr.setValue('parent', parents[i]);
    gr.setValue('type', '<your_type_sys_id>');
    gr.insert();
}

 

 

Cheers,

Tai Vu

Hervi
Tera Contributor

This is not creating record . Also, its just redirecting me to form view of that table.