- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 06:35 AM
Can someone help me with the widget controller and server script to update a record with the values from inputs? I want to update my record when I click the submit button. See screenshot below to see my html. Many thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 07:45 AM
You can insert a record using below code. Note that I have made slight changes in the HTML as it did not include ng-model first. Also, this code is might not be following high coding standards, but will work, please make changes accordingly. I would also suggest you to rename your input tag Id's so that they are much more readable and make the UI responsive if this is actually going into production environment.
HTML Code:
<div class="widget-container">
<div class="widget">
<h2>Widget Input Form</h2>
<div>
<div class="form-group">
<label for="input1">Monday: </label>
<input type="text" id="input1" ng-model="c.data.input1" placeholder="Enter Value">
</div>
<div class="form-group">
<label for="input2"></label>
<input type="text" id="input2" ng-model="c.data.input2" placeholder="Enter Value">
</div>
<div class="form-group">
<label for="input3"></label>
<input type="text" id="input3" ng-model="c.data.input3" placeholder="Enter Value">
</div>
<div class="form-group">
<label for="input4"></label>
<input type="text" id="input4" ng-model="c.data.input4" placeholder="Enter Value">
</div>
<div class="form-group">
<label for="input5"></label>
<input type="text" id="input5" ng-model="c.data.input5" placeholder="Enter Value">
</div>
<button type="submit" ng-click="c.addRecord()">Submit</button>
</div>
</div>
</div>
Client Controller:
api.controller=function($scope) {
/* widget controller */
var c = this;
c.addRecord = function()
{
alert($scope.c.data.input1);
c.data.input1 = $scope.c.data.input1;
c.data.input2 = $scope.c.data.input2;
c.data.input3 = $scope.c.data.input3;
c.data.input4 = $scope.c.data.input4;
c.data.input5 = $scope.c.data.input5;
c.data.action = "ACTION"
c.server.update().then(function(response){
alert("Thank You for submitting the record");
})
}
};
Server Script:
(function() {
if(input && input.action=='ACTION'){
var insertRecord = new GlideRecord("table_name");
insertRecord.initialize();
insertRecord.field_name = input.input1;
insertRecord.field_name = input.input2;
insertRecord.field_name = input.input3;
insertRecord.field_name = input.input4;
insertRecord.field_name = input.input5;
insertRecord.insert();
gs.addInfoMessage('Record Inserted');
}
})();
If you feel this has helped you a bit, you may mark the answer as helpful or accept it as a solution.
Regards,
Pranav T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 07:45 AM
You can insert a record using below code. Note that I have made slight changes in the HTML as it did not include ng-model first. Also, this code is might not be following high coding standards, but will work, please make changes accordingly. I would also suggest you to rename your input tag Id's so that they are much more readable and make the UI responsive if this is actually going into production environment.
HTML Code:
<div class="widget-container">
<div class="widget">
<h2>Widget Input Form</h2>
<div>
<div class="form-group">
<label for="input1">Monday: </label>
<input type="text" id="input1" ng-model="c.data.input1" placeholder="Enter Value">
</div>
<div class="form-group">
<label for="input2"></label>
<input type="text" id="input2" ng-model="c.data.input2" placeholder="Enter Value">
</div>
<div class="form-group">
<label for="input3"></label>
<input type="text" id="input3" ng-model="c.data.input3" placeholder="Enter Value">
</div>
<div class="form-group">
<label for="input4"></label>
<input type="text" id="input4" ng-model="c.data.input4" placeholder="Enter Value">
</div>
<div class="form-group">
<label for="input5"></label>
<input type="text" id="input5" ng-model="c.data.input5" placeholder="Enter Value">
</div>
<button type="submit" ng-click="c.addRecord()">Submit</button>
</div>
</div>
</div>
Client Controller:
api.controller=function($scope) {
/* widget controller */
var c = this;
c.addRecord = function()
{
alert($scope.c.data.input1);
c.data.input1 = $scope.c.data.input1;
c.data.input2 = $scope.c.data.input2;
c.data.input3 = $scope.c.data.input3;
c.data.input4 = $scope.c.data.input4;
c.data.input5 = $scope.c.data.input5;
c.data.action = "ACTION"
c.server.update().then(function(response){
alert("Thank You for submitting the record");
})
}
};
Server Script:
(function() {
if(input && input.action=='ACTION'){
var insertRecord = new GlideRecord("table_name");
insertRecord.initialize();
insertRecord.field_name = input.input1;
insertRecord.field_name = input.input2;
insertRecord.field_name = input.input3;
insertRecord.field_name = input.input4;
insertRecord.field_name = input.input5;
insertRecord.insert();
gs.addInfoMessage('Record Inserted');
}
})();
If you feel this has helped you a bit, you may mark the answer as helpful or accept it as a solution.
Regards,
Pranav T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 07:47 AM
Also, In case you miss out, I have changed the function name to
ng-click="c.addRecord()"
Instead of ng-click="c.save()" in your original html.