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:35 AM
Hello @DB1 ,
can you replace input.firstname with
input.n.firstname
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 06:40 AM
are you sure the value you got is working correct?
check this
Communicating between the Client Script and the Server Script of a widget
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 06:45 AM
update as this and check once
graddexuser2.addQuery('first_name',input.n.fistname.value);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 09:45 AM
Hi @Ankur Bawiskar
I'm facing issue here when same code I'm using and Running in Global scope it is working fine
But when same code in running & Implementing in Scoped Application then this code is not working and not showing the output in Console on server side
HTML Code
<form>
<input type="text" name="chkRow" ng-model="c.data.half_day" />
<input type="submit" value="Submit" ng-click="c.update()">
</form>
Client Side Script
api.controller = function () {
var c = this; c.data.half_day = 'ABC'; c.update = function () {
c.data.action = 'Test'; c.server.update().then(function (response) {
console.log(response);
});
}
};
Server Side Code
(function () {
if (input && input.action === 'Test') {
console.log(input.half_day);
}
})();
I'm also trying to used gs.info() , gs.log() on server side
Thanks & Regard
Abhijeet Burghate