UI Action to update incident with a related list record number

oharel
Kilo Sage

Hi all,

My incident form has a related list called kb, where knowledge articles are shown. The articles are filtered according to the category and area of the incident.

I am looking for a UI Action to update my incident's work_notes upon choosing a record from related list on the incident form.

I am not able to get the sys_id of the kb record I chose in order to insert it into the incident's work_notes.

When the UI action on the incident form is on the related list table (RP.isRelatedList()), I can either get the id of the incident form (client side) or the id of the kb using server side script. But not both.

Any help would be appreciated.

Harel

1 ACCEPTED SOLUTION

Got you.You need to write a client side code in the UI action and call script include and return all the values you need from the checked article and save it on to the form. Here is a sample script that will get you the information from related problem record and updates the description on to the parent incident record.



UI Action Code:


function getNumber(){


  var id=g_list.getChecked();


  var ga = new GlideAjax('GetDetails');


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


  ga.addParam('sysparm_ids',id);


  ga.getXML(callBack);


  function callBack(response){


  var answer = response.responseXML.documentElement.getAttribute("answer");


  g_form.setValue('description',answer);


  g_form.save();


  }


}



Script Include:


var GetDetails = Class.create();


GetDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {


getNumber: function(){


  var gr= new GlideRecord('problem');


  gr.get(this.getParameter('sysparm_ids'));


  return gr.number;


},


      type: 'GetDetails'


});


View solution in original post

12 REPLIES 12

Absolutely. Is this what you are looking for?



var GetDetailsUseless = Class.create();  


GetDetailsUseless.prototype = Object.extendsObject(AbstractAjaxProcessor, {  


  getNumber: function(){  


 


  var ids = this.getParameter('sysparm_ids');  


  var list = [];  


  var gr= new GlideRecord('u_incident_kb');  


 


 


  gr.addQuery('sys_id', 'IN', ids);  


  gr.query();  


  while(gr.next()) {  


  list.push('\n'+gr.u_kb_number.getDisplayValue()+'\n');  


  }  


  return list.join();  


  },  


      type: 'GetDetailsUseless'  


});  




Ui action:


function getNumber() {  


  var id = g_list.getChecked();  


  jslog('list is ' + id);  


  var ga = new GlideAjax('GetDetailsUseless');  


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


  ga.addParam('sysparm_ids',id);  


  ga.getXML(callBack);  


 


  function callBack(response) {  


  var answer = response.responseXML.documentElement.getAttribute("answer").replace(/,/g,'');  


  g_form.setValue('work_notes', 'This KB did not help me resolve the incident: ' + answer);  


  g_form.save();  


  }  


}  


Awesome!


Thanks,


Harel


Hi Abhiney i have to create a similar functionality but not with UI action but while the list gets updated i want to update the description at the moment.

 

Can we achieve this?