Auto populating value from one table to other using UI page.

sowmyaj
Giga Expert

Hi All,

                  According to requirement I have some dropdown feild in first "Div tag" with "Run" button. When I click on "Run" button, it will display "Second div values".

                            In "second div" I have a "save button" on clicking it will store selected "first div values into "colorTable" table, Where ColorID is autogenerated.

                            In "Third div" I have "Add button" on clicking it will POP-UP "Observation table". where colorID should be auto fetched from "ColorTable" and I'm struggling in autopopulating the colorID in "ObservationTable".   Please have a look... Except that other functionalities are working.

                            I have also created client script by referring to the below thread

                                                                                                  https://community.servicenow.com/thread/195466

                               

                                Below is my code and in the bolded part I don't have clear idea. Can anyone please help me!!!

IN UI page,

Html part,

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<html>
<body>
        <g:ui_form id="form" name="form">
            <div id="firstpage">

                  <table>

                        <tr>

                            <td>
                                          Scope:
                            </td>

                            <td>  
                                      <select name="perf_select" id="perf_select">
                                          <option value="red">red</option>
                                          <option value="yellow">yellow</option>
                                          <option value="blue">blue</option>
                                      </select>
                              </td>

                      </tr>
                      <tr>  
                              <td>
                                          <button type="button"   id="run" onclick="display()" >Run</button>
                              </td>

                      </tr>
              </table>
      </div>

  <div id="secondpage">
                <table>
                              <tr>
                                      <td> <button type="button"   id="run" value="submit"   onclick="save()" >Save</button></td>
                              </tr>
                            <tr>  

                                                some datas from based on requirement
                              </tr>

                  </table>

    </div>


    <div id="thirdpage">

          <g2:evaluate var="jvar_obs">
                var obs = new GlideRecord('u_observation');
                obs.query();
            </g2:evaluate>
        <table>
                    <tr>

                          <!-- What changes need to be done??-->
                              <td><a href="u_observation.do?sysparm_colorId=${"I need to fetch the color ID stored in the table for the particular value from colorTable".u_colorid}"><button type="button"   id="popup" value="submit" onclick="popupDispList()"><b>Add</b></button></a></td>
                    </tr>
                    <tr>
                                <th><b>Date<br/></b> </th>
                                <th> <b>Observations </b></th>

                    </tr>
                    <j2:while test="$[obs.next()]">
                    <tr>

                                      <td>$[obs.u_date] </td>
                                          <td>$[obs.u_observation] </td>

                  </tr>
                    </j2:while>
</table>

  </div>
</g:ui_form>
</body>

</html>


</j:jelly>

Client script is

function display(){
displaying second div
 
}

function save()

{

//Color id is auto generated when the values are inserted into table. This ID I need to fetch and store in Observation table when "ADD" button is clicked

var gr = new GlideRecord('u_colorTable');

  gr.initialize();

  gr.u_color =document.getElementById("perf_select").value;

  gr.insert();

}
function popupDispList() {
   
      var gdw = new GlideDialogWindow('display_u_observation_list');
      gdw.setTitle('Observations');
      gdw.setPreference('table', 'u_observation');
      gdw.setPreference('sysparm_view', 'default');
  gdw.setSize(750,300);
   
      gdw.render();

}

1 ACCEPTED SOLUTION

Hi Sowmya,



i have made it working. first i have made add() function which will be triggered when user clicks ADD button.


in that script we are making GlideAjax call beacuse query is not working at client side.



here is add function.


function add(){


        var ga = new GlideAjax('getcolor');


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


        ga.getXML(myfunc);



function myfunc(response) {


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


   


  alert(answer);


}


we dont need this callback function but i added just for testing purpose.


now find below script include.make sure u check 'client' check box



var getcolor = Class.create();


getcolor.prototype = Object.extendsObject(AbstractAjaxProcessor, {




  getid:function (){


  var qr = new GlideRecord('u_colortable');


  qr.orderByDesc('u_number');   //sort by last entry in table. change field name with ur field name.


  qr.query();


  var answer;



  if(qr.next()){


  answer = qr.getValue('u_number'); //u_number is colorID field in my table(autogenerated).


  }


   


  var gr1 = new GlideRecord('u_observation');


  gr1.initialize();


  gr1.u_colorid =answer + '';


  gr1.insert();



  return answer;


  }



});



i hope it will work. please make correct/helpful if it worked.


thanks,


Rushit Patel


View solution in original post

20 REPLIES 20

Hi Rushit,



                  After the add button is clicked, I need to store some details in fields of u_observation table and in that the u_car_id will be last value of u_carid in u_car table. So I need to navigate to u_observation table in the same functionality to fill the other fields of u_observation table.



Thank you,


Sowmya


Hi Sowmya,



to edit the record in observation table u can use code which u posted in original question which used Glide dialog window. add that code in the end of add function.


glide ajax is working? are records being created in observation table?


Hi Rushit,



                            Nope.. Still it is not working.     Onclick functionality is not working properly.. Are you finding any mistake in the code I posted??   can you check once html code I posted. Can I pass parameter in it?       I know I'm trobuling you lot but please look into that.



Thank you.


Hi sowmya,



not even record with empty fields is getting inserted? it is working in my instance.


remove   response.sendRedirect("u_observation.do");   from script include.


Hi rushit,



not even empty value is getting inserted.   I removed and tried. Still not working.