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

Hi Geoffrey,



Thanks for the reply. Abhinay provided the answer , and yes, if I understand correctly, this is a GlideList2 function thing.


Harel


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'


});


Hi Abhinay,



With a little modification, I was able to implement the script. Then using another reply of yours to another thread, I also implemented a solution where if you choose more than one record, they are updated in the work_notes as well.



Below is the code, if anyone needs it:


UI Action: Useless


Client: true


Onclick: getNumber();


Condition: RP.isRelatedList()


Script:


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");


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


  g_form.save();


  }


}



Related script include:


Name: GetDetailsUseless


Client callable: true


Script:


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(gr.u_kb_number.getDisplayValue());


  }


  return list.join();


  },


      type: 'GetDetailsUseless'


});



If you have an idea how to improve the script, feel free.


Thanks,


Harel


Abhinay Erra
Giga Sage

Glad you got this working. And your script looks perfect


Thanks.


By the way, is there a way to make the records appear each in a new line? I tried in the script include:


while(gr.next()) {


list+='\n' + gr.sys_id + '\n';


}


return list;


},



but all I got was the two sys_ids one after the other with a space between them.



harel