Input to server coming as undefined in widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 01:39 AM
Hi,
I'm trying to create a custom widget which will take input from user and based on it will provide count of incident records. For that I wanted to pass the user input to server side script.
HTML:
<div>
<!-- your widget template -->
<span class="sn-canvas-header-tools" >Task Overview</span>
<div>
<table>
<tr>
<th class ="required">Owning Business</th>
</tr>
<tr>
<td>
<select ng-model="data.owningBusiness" required onchange="myMarket()">
<option id = 'am' ng-model = 'c.data.fname' ng-repeat="i in data.market" value={{i}}>{{i}}</option>
</select>
</td>
<td><button class="button" id = 'button1' type = 'submit' ng-click = 'ApplyFilter()' >Filter</button></td>
</tr>
</table>
</div>
</div>
Client script:
api.controller=function($scope, $rootScope) {
/* widget controller */
var c = this;
c.data = $scope.data;
c.server.update();
$scope.ApplyFilter = function() {
//alert("count1: " + c.data.count1);
var che = document.getElementById('am').text;
alert("value: " + che);
c.data.trigger = true;
c.data.ob = 'OwB'
c.server.update().then(function(){})
}
Server script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 02:40 AM
Hi @kanishkab
try the below code
HTML
<div>
<!-- your widget template -->
<span class="sn-canvas-header-tools" >Task Overview</span>
<div>
<table>
<tr>
<th class ="required">Owning Business</th>
</tr>
<tr>
<td>
<select ng-model="data.owningBusiness" required onchange="myMarket()">
<option id = 'am' ng-model = 'fname' ng-repeat="i in data.market" value={{i}}>{{i}}</option>
</select>
</td>
<td><button class="button" id = 'button1' type = 'submit' ng-click = 'ApplyFilter()' >Filter</button></td>
</tr>
</table>
</div>
</div>
clientside code
api.controller=function() {
/* widget controller */
var c = this;
$scope.ApplyFilter = function() {
//alert("count1: " + c.data.count1);
var obj={};
obj.fname= c.fname;
alert("value: " + obj.fname);
obj.trigger = true;
obj.ob = 'OwB';
c.server.update(obj).then(function(){
});
};
};
server-side code
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.owningBusiness = $sp.getParameter('owningBusiness');
var userGr = new GlideRecord('sys_user');
userGr.addQuery('sys_id', gs.getUserID());
userGr.query();
if (userGr.next()) {
var associatedMarket = userGr.getDisplayValue('u_associated_markets');
if (associatedMarket !== null) {
data.market = associatedMarket.split(',');
}
}
if (input.ob) {
$sp.log('this'+ input.fname);
}
})();
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 04:28 AM
Not getting any output with this, instead getting error on line 16 saying cannot read ob from undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 05:11 AM
server-side ya client side
Thanks
dgarad