How do I get the Input value(date/time)and update a incident field with that value in a widget

SD40
Tera Contributor

 

When the user clicks the update button with the date/time, that value should update a field in the incident table.

Html........

<div>
<form>
<sp-date-picker name="mydata" sn-include-time=true field="c.fromDate" ng-model="c.fromDate.value" ></sp-date-picker>
<div class="m-t-lg">
<button class="btn btn-primary pull-right" ng-click="UpdateData()">
${Update}
</button>
</div>
</form>

</div>

 

Client side....

api.controller=function($scope) {
/* widget controller */
var c=this;
c.fromDate = {
displayValue: '',
value: c.data.mydata,
name: ''
};
$scope.UpdateData = function(){
c.server.update();
}
}

 

Server side

(function() {

// If input is submitted then grab any input values from input fields
// based on their names (name attribute on element)
// and update this case a record
if(input){
var inc1 = new GlideRecord('incident');
inc1.get(sys_id);
inc1.setValue('field_name', input.mydata);
inc1.update();
}
})();

1 ACCEPTED SOLUTION

Filipe Cruz
Kilo Sage
Kilo Sage

Hello Ed,

Solution tested in a PDI!!


Change your client script by the following one:

api.controller=function($scope) {
	/* widget controller */
	var c=this;
	c.fromDate = {
		displayValue: '',
		value: c.data.myInput,
		name: ''
	};
	$scope.UpdateData = function(){
		var input = {};
		input.myInput = c.fromDate.value;
		c.server.get(input);
	}
}

Basically, I declared object "input" and instead of c.server.update() I used c.server.get(input).

It worked!

Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

View solution in original post

2 REPLIES 2

Filipe Cruz
Kilo Sage
Kilo Sage

Hello Ed,

Solution tested in a PDI!!


Change your client script by the following one:

api.controller=function($scope) {
	/* widget controller */
	var c=this;
	c.fromDate = {
		displayValue: '',
		value: c.data.myInput,
		name: ''
	};
	$scope.UpdateData = function(){
		var input = {};
		input.myInput = c.fromDate.value;
		c.server.get(input);
	}
}

Basically, I declared object "input" and instead of c.server.update() I used c.server.get(input).

It worked!

Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

SD40
Tera Contributor

One issue I have noticed is that if I select a date/time like this below-

but after updating the data, it updates that field value with 03-11-2022 18:08:29

any solution for this??