- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2018 10:04 AM
I've created a custom widget and the purpose of it is to execute a rest api call from server side code and get the access token(server side) and pass it to client controller script to perform SSO with a third party vendor. I'm able to execute both scripts separately and got logs for it. All I need is to pass the token and user's email through variables from server side to client controller script, I've created the data object in server side script and using $scope or c.variable to retrive the data, but I'm not getting the data back to client script.
Here is an example code:
server side:
(function() {
data.name = [];
// get current user email
var uemail;
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', gs.getUserID());
usr.query();
if(usr.next())
{
uemail = usr.email;
}
data.name.push({email: uemail});
gs.log("server side user>>>" +uemail + "and " + data.name, "Test code");
})();
client code:
function($scope) {
var c = this;
var temp = c.data.email;
alert("client code>>>" +temp); // not working
}
Do I need to define anything in the HTML template? I've included <input type="text" ng-model="c.data.name"/> in HTML too, but wont work. Any help is appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2018 10:26 AM
Did you try this code?
server side:
(function() {
data.name = '';
data.email = '';
data.code = '';
// get current user email
var uemail;
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', gs.getUserID());
usr.query();
if(usr.next())
{
data.email = usr.email;
data.code = 'your code';
}
//data.name.push({email: uemail});
//gs.log("server side user>>>" +uemail + "and " + data.name, "Test code");
})();
client code:
function($scope) {
var c = this;
var temp = c.data.email;
alert("client code>>>" +temp); // not working
alert("client code>>>" +c.data.code); // not working
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2019 08:17 PM
Can you also set the data.count to 0 in Server Script
data.count = 0;
var gaIncCount = new GlideAggregate('incident');
gaIncCount.addQuery('active','true');
gaIncCount.addQuery('assignment_group','f57bbd87ebff23008f833c4fea887e46');
gaIncCount.addQuery('contact_type','walk-in');
gaIncCount.addAggregate('COUNT');
gaIncCount.query();
var count = 0;
if(gaIncCount.next()){
count = gaIncCount.getAggregate('COUNT');
console.log('row count is '+count);//shows correctly
data.count = gaIncCount.getAggregate('COUNT'); //this is what I need to send to client
console.log('data.count is '+data.count);//shows correctly
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2019 09:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2019 09:55 PM
Hi again Sanjiv,
I figured it out, I needed to move the data.count to be inside the "c.server.update()" function...got it working. Here's my final client script:
function($scope, spUtil, $window) {
var c = this;
c.data.user = {value:'',displayValue:''};
c.click = function(){
c.data.user.displayValue='';
c.data.user.value='';
c.data.short_description = '';
}
c.addItem = function(){
var user = c.data.user.value;
var desc = c.data.short_description;
if(user == '' || user == 'undefined' || user == 'null' || desc == 'null' || desc == '' || desc == 'undefined'){
alert('Please enter your name and a description of your issue before submitting.');
return;
}
c.server.update().then(function(response){
var queueNumber = c.data.count; //needed to move this here
spUtil.addInfoMessage('Thank you, a ticket has been created on your behalf. You are number '+queueNumber+'. You will now be redirected to the Tech Hub home screen.');
setTimeout(myFunction, 3000);
function myFunction(){
$window.location.href = 'https://dev54219.service-now.com/th_proto?id=techhub_index';
}
c.data = {};
$scope.c.affected_user.value = '';
}) }
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2019 09:56 PM
thanks again as always!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2019 09:58 PM
Maybe one more question in case you've got time...any idea how I can get rid of those errors in the console.log? the script is working, but I'd like it to work without the errors. Any thoughts? thanks!