How can I get the values on a selected row in a list?

hsantana8
Giga Contributor

I am able to get the selected rows in a list using the following code:

function onClick()

{

        var checked = g_list.getChecked();

        var rowsArray = new Array();

        rowsArray = checked.split(",");

}

The question is how can I access the individual values on each column of the row?

1 ACCEPTED SOLUTION

Got it working, in the example code the problem was in the variable name 'instanceVal' didn't match 'instance'.



Client Side: Pass the sys_id   of the row using a UI Action.


Server Side: Return the column of the row detected by sys_id.


View solution in original post

5 REPLIES 5

Chuck Tomasi
Tera Patron

Hi Hugo,



I recommend that you use the array to do a GlideAjax call and get back an array of record field/value pairs in a JSON object. See Episode 33 of TechNow for an example how to do that.



TechNow Episode List


Thanks for your answer.



Users can only select 1 row at a time, not multiple rows. Is GlideAjax still the fastest way to do this?


Yes. If you are going from a client script, then GlideAjax is your best method of retrieving server information.


This is what I have so far, trying to get the value from the field instance on the selected row. It returns null.



1. Client script in a UI Action:



function onClick(){



        var checked = g_list.getChecked();


        var rowsArray = new Array();


        rowsArray = checked.split(",");



        if(rowsArray[0]==''){


                  alert("No Rows selected");


                  return;


          }



        if(rowsArray.length>1){


                  alert("More than one record selected");


                  return;


        }



        alert("Row Sys Id: " + rowsArray[0]);



        //Test


        var instanceVal = rowsArray[0];


        var ga = new GlideAjax('InstanceMapper');


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


        ga.addParam('sysparm_instanceVal', instanceVal);


        ga.getXML(stateCallback);



        function stateCallback(response){


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


                  alert(answer);


        }


}



2. Server Side script



var InstanceMapper = Class.create();


InstanceMapper.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {


     


        getInstance : function (){


                  var instanceVal = this.getParameter('sysparm_instanceVal');


                  var mapTableName = 'x_177822_.....';



                  var map = new GlideRecord(mapTableName);


                  map.addQuery('instance', instanceVal);


                  map.query();



                  if(map.next()){



                            return map.instance.getDisplayValue();


                  }


},



type: 'InstanceMapper'


});



Possible problems:



- I am not using a client script, instead I am adding the script in the UI Action. Could this cause problems? The reason is I want to trigger the script when the user clicks the button I created. Not on submit/onload/etc.



- In the server side, this line "map.addQuery('instance', instanceVal);" should have the name of the table column as the first parameter? the label of the column? I am not clear on this parameter.



Any help will be very appreciated.