Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

VigneshMC
Mega Sage

Try this

client

function($scope,spUtil) {

alert($scope.data.approveMsg);

}

 

Hi Vignesh,

 

I tried, but it is not working,

Client Side:

function() {
var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;

})

}

function($scope,spUtil) {


alert($scope.data.approveMsg);


}
}

can you provide the screenshot or xml of your widget?

sai krishna10
Giga Guru

Attached the xml of the widget