how to pass client side input to server side in ServiceNow portal Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 06:25 AM
Hello All,
I have client side and server side scripting and I am trying to pass the input from client to server (script attached below).
I do get the first info message however not the second one. Need help on the same to pass the sysid of firstname from client to Server
Client:
c.openexistingUserform=function(){
c.n={
"firstname" :'',
"busiphone" : '',
"email1": '',
"city1": ''
}
console.log("openexistingUserform" ,c.n);
c.data.action = 'addphUser';
c.server.update();
document.getElementById("addexUserForm").style.display = "block";
}
I get the following output from the console
- busiphone: "(555) 555-0004"
- city1: ""
- email1: "abraham.lincoln@example.com"
- firstname: {value: 'a8f98bb0eb32010045e1a5115206fe3a', displayValue: 'Abraham Lincoln'}
- [[Prototype]]: Object
Server
if(input&&input.action=='addphUser')
{
gs.addInfoMessage("addphUser");
var graddexuser2 = new GlideRecord('sys_user');
graddexuser2.addQuery('sys_id',input.firstname);
graddexuser2.query();
if(graddexuser2.next())
{
gs.addInfoMessage("User " +graddexuser2.user_name);
//data.existingUser.push({email:graddexuser2.email.toString(),busphone:graddexuser2.phone.toString()});
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 06:51 AM
Try the below change:
Client Script
c.openexistingUserform=function(){
c.data.n={
"firstname" :'',
"busiphone" : '',
"email1": '',
"city1": ''
};
console.log("openexistingUserform" ,c.n);
c.data.action = 'addphUser';
c.server.update();
document.getElementById("addexUserForm").style.display = "block";
}
Server Script:
if(input&&input.action=='addphUser')
{
gs.addInfoMessage("addphUser");
var graddexuser2 = new GlideRecord('sys_user');
graddexuser2.addQuery('first_name',input.n.firstname);
graddexuser2.query();
if(graddexuser2.next())
{
gs.addInfoMessage("User " +graddexuser2.user_name);
//data.existingUser.push({email:graddexuser2.email.toString(),busphone:graddexuser2.phone.toString()});
}
}
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 08:39 AM - edited 11-22-2022 09:04 AM
Thanks @Ankur9 , @Mohith Devatte and @palanikumar Actually the above solution did not work for some reason. I also have an Onload script to populate the data everytime the name is selected from the form as below
var c = this;
$scope.$on("field.change", function(evt, parms) {
//console.log(parms.newValue);
c.data.usersysid = parms.newValue;
if(parms.newValue =='')
{
c.n.email1 = '';
c.n.busiphone = '';
c.n.city1 = '';
c.n.firstname = '';
}
else{
c.data.action = 'fetchexistingUser';
c.server.update().then(function(){
c.n.email1 = c.data.existingUser[0].email;
c.n.busiphone = c.data.existingUser[0].busphone;
});
}
});
And then I have the script to hold the values of the data
c.openexistingUserform=function(){
c.data.n={
"firstname" :'',
"busiphone" : '',
"email1": '',
"city1": ''
};
console.log("openexistingUserform" ,c.n);
c.data.action = 'addphUser';
c.server.update();
document.getElementById("addexUserForm").style.display = "block";
}