- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 02:33 AM
Hi All,
I've created a custom field using HTML and now i want to get the value being input in that field towards the server side in Service Portal.
HTML Part:-
<div>
<img ng-src="{{::c.data.logo}}" />
<a href="?id={{::c.data.homepage}}">Click here to go home</a>
</div>
<div>Enter your Last name:
<input type="text" ng-model="c.data.lastname" id="LN" ng-change="c.displayNew()"/>
<h2>{{ c.data.messageNew }}</h2>
</div>
Client Side Part:-
function() { | ||||
var c = this; | ||||
c.displayNew = function(){ | ||||
c.data.messageNew = (c.data.lastname) ? 'Hello ' + c.data.lastname + '!' : ''; | ||||
} | ||||
c.display(); | ||||
c.server.update(); |
}
Server Side part:-
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
console.log("Server Side"+input);
var portalGr = $sp.getPortalRecord();
console.log("Server Side"+portalGr);
})();
Any idea how to get the "Last Name" which is being input to the server side for further validations.
Any help is appreciated.
Regards,
Dhruv Chandan
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 06:19 AM
Hi Dhruv,
You're close here. When using server.update() the data object is represented by the input object, so you would typically do something like this on the server:
if (input) {
console.log("Server Side: " + input.lastname);
}
You don't need to write input.data, and service portal is unique in that it lets you use console.log() on both the client and server side script areas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 03:04 AM
Hi
You are quite close. On the server side you get the input via "input.data.lastname".
Also see this for inspiration:
https://serviceportal.io/communicating-between-the-client-script-and-the-server-script-of-a-widget/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 03:45 AM
Hi Lars,
I tried "console.log("Server Side"+input.data.lastname);"
but it showing up as undefined in the logs even with the entries filled in.
Regards,
Dhruv Chandan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 04:27 AM
console.log is a client-side only javascript command
input.data. is server-side only
You can't mix the two.
You can do a gs.log though, then look through your servicenow logs to find what you're trying to see.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017 05:16 AM
Hi David,
gs.log("Server Side"+input.data.lastname,"dc31");
Used the above statement in the sever side code and the system logs is still showing it as undefined.
Regards,
Dhruv Chandan