Alert Message in service portal

sai krishna10
Giga Guru

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

1 ACCEPTED SOLUTION

This work for me.

To avoid object error , update the server code to 

data.approveMsg = rc.number.toString();

View solution in original post

9 REPLIES 9

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);

})

When i used your code this is printing as below

 

find_real_file.png

 

But i want to print the value present in server side.

This work for me.

To avoid object error , update the server code to 

data.approveMsg = rc.number.toString();

Hi 

try with this once :- 

alert($scope.data.approveMsg);

sai krishna10
Giga Guru

Thanks Vignesh,

This is working Now.