Unable to get current value from input field on Service Portal widget.

forrestfalk
Giga Contributor

Hello,

I am trying to load the short description from a ticket and load it into the short description input field. I am able to load the ticket's short description into the field, but I am unable to get the updated input when the user changes it. I added an ng-change function to check the value and I keep getting the old value. I'm not sure if I am missing assigning the new value or what is wrong. I also get the old value when I put console.log(input.short_description.value); at the beginning of the server script. Can you please help me get the current value of the input in the short description field.

Thank you for your help!

Forrest

HTML:

<input class="form-control" id="short_description" ng-model="short_description" ng-change="_changed()">

Client Script:

$scope.short_description = $scope.data.short_description.display_value;

$scope._changed = function(){

alert($scope.short_description);

}

Server Script:

var gr = $sp.getRecord();

data.short_description = $sp.getField(gr, 'short_description');

1 ACCEPTED SOLUTION

Rama Chandra D
Kilo Guru

Hi Forrest,



How does the user update the short description? For any update on the client sider, server.update() should be called (from client scripts) for the 'data' object to get updated. Since, there isn't any update call in your script, the alert displays the values in the data object when the form loaded and server script is executed.



Darshak


View solution in original post

2 REPLIES 2

Rama Chandra D
Kilo Guru

Hi Forrest,



How does the user update the short description? For any update on the client sider, server.update() should be called (from client scripts) for the 'data' object to get updated. Since, there isn't any update call in your script, the alert displays the values in the data object when the form loaded and server script is executed.



Darshak


Thank you so much for the help! Here is the final code in case someone else needs it.



HTML:


<button id="saveButton" type="button" style = "margin-top: -35px; color: #2dc7ff; background-color: #ffffff;" class="btn bg-primary pull-right" ng-click="saveRecord()">Save</button>


<label class="m-n" for="short_description">Short Description</label>


<input class="form-control" id="short_description" ng-model="short_description">





Client Script:


function($scope, spUtil) {



$scope.short_description = {


displayValue: $scope.data.short_description_name,


value: $scope.data.short_description_value,


name: 'short_description'


};



$scope.short_description = $scope.data.short_description.display_value;  



$scope.saveRecord = function(){


$scope.data.save_button_value = 'true';


alert('Short Description: ' + $scope.short_description);


$scope.data.short_description_value = $scope.short_description;


$scope.server.update().then(function(response) {                


              spUtil.update($scope);      


      });


};



Server Script:


(function() {


console.log('Input: ' + input.short_description_value);


var gr = $sp.getRecord();


data.short_description = $sp.getField(gr, 'short_description');


}