
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2018 03:36 AM
Hi,
I created a button on the page. Once the user clicks on the button i want to call the server side function. once the function is executed it sends one value and i want to alert that value in client script in service portal
so i wrote the script.
Client script:
function() {
var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
alert(c.data.approveMsg);
}
}
Server Side:
(function() {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
gr.addQuery('sys_id',data.sys_id);
gr.query();
if(gr.next()){
gs.addInfoMessage(gr.number);
data.approveMsg = gr.number;
}
Here Once i clicked on the button i am getting the alert as undefined and then i was getting the info Message. But my requirement is once i click on the button i want to alert the server side value. Pls help me on this
Thanks
Sai Krishna
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2018 04:33 AM
This work for me.
To avoid object error , update the server code to
data.approveMsg = rc.number.toString();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2018 04:25 AM
Hi
Undefined is maybe coming because it cannot find the c.data.approve or maybe it is not defined anywhere.
Try printing it here in your code : -
c.server.update().then(function() {
c.data.action = undefined;
alert(c.data.approveMsg);
})

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2018 04:31 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2018 04:33 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2018 04:38 AM
Hi
try with this once :-
alert($scope.data.approveMsg);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2018 04:36 AM
Thanks Vignesh,
This is working Now.