- 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-11-2015 05:03 AM
Hi Sowmya,
you are saying that when u press 'SAVE' button,record will be created in u_colorTable and ID(number) will be autogenerated along with it. but I don't understand the meaning of <a>tag. and why you are displaying glide from in add() method.
and these three name of the ids are firstpage,secondpage,thirdpage so your actual requirement is to have 3 different UI page?
thanks,
Rushit Patel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2015 06:37 AM
Hi rushit,
In simple way, I need to store some observations in "u_observation" table with the reference of colorID and that colorID should be the latest value in "u_colortable" table
I will give you table structure.
Table: u_colortable
Column name values
ColorId autogenerated number
Color the drop down selection value will be added after save button is clicked
Table: u_observation
Column name values
ColorId This color ID should be present/latest ColorId from u_colortable which will be automatically get saved. User can't edit this column.
date system date
observation Manaully observations will be added by user
I tried <a> tag to fetch the current carID from u_colortable table and to store it in u_observation table by passing as argument. I'm not having clear idea on it.. Please tell me how can I do?
- 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:11 PM
Hi Rushit,
Sorry for the late response. May I know is there any other way in SN except Ajax call. If there, please help me out. Can I get the last record id using insertWithReferences()? Please guide with other possible solutions.
Thanks & Regards,
Sowmya.