- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2015 03:29 AM
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();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2015 07:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2015 10:45 PM
HI sowmya,
for that... colorTable must have reference field of observation table. but even after doing that ur requirement is to set colorID field(in observation table) with autogenerated value. that value will be generated after u execute insertWithReferences() command on colortable. so I think u will have to insert separately.
Regards,
Rushit patel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2015 11:03 PM
Ok.. Thank you so much....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 12:20 AM
Hi Sowmya,
did that code work?
can you please mark my answer if it was helpful.
thanks,
Rushit Patel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 01:21 AM
Hi Rushit,
Check my below code. I followed you but it is not working. As I don't have depth idea in AJAX I'm not able to find the error. Please look into this.
Html
<button style="border-radius:10px;" type="button" id="add" value="submit" onclick="add(carId)"><b>Add</b></button>
Client script
function add(carId){
var ga = new GlideAjax('getCarDetails');
ga.addParam('sysparm_name','getCarId');
var getCarDetails = Class.create();
getCarDetails.prototype = Object.extendsObject(AbstractAjaxProcessor,
{
getCarId:function ()
{
var qr = new GlideRecord('u_car');
qr.orderByDesc('u_carid'); //sorting by last entry in table.
qr.query();
var answer;
if(qr.next())
{
answer = qr.getValue('u_carid'); //u_carid' is id field in my table u_car which is autogenerated.
}
var gr1 = new GlideRecord('u_observation');
gr1.initialize();
gr1.u_car_id=answer + ''; //u_car_id is the id in observation table.
gr1.insert();
return answer; } });
response.sendRedirect("u_observation.do");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 01:40 AM
Hi Sowmya,
in client script u are not executing ajax call. ga.getXML(); line is missing.
and why u have written this line response.sendRedirect("u_observation.do"); in script include?
Regards,
Rushit patel