Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Date Picker in widget is not showing correct date in portal

Jaya Srivastava
Tera Contributor

Hello,

I have created a date picker in widget that will take input date from user. The date picked by the user updates a field in Approval table. But it is updating wrong date, it is updating one previous date like if I enter 24 it updates 23 in that field of Approval table. What am I missing?

1 ACCEPTED SOLUTION

Try this code

HTML

<sp-date-picker name="mydata" sn-include-time=false field="c.fromDate" ng-model="c.fromDate.value" ></sp-date-picker>
<button class="btn btn-primary" ng-click="UpdateData()">
${Save}
</button>

 

Client

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);
	}
}

 

Server

(function() {

if(input){
var inc1 = new GlideRecord('your_table');
inc1.get('recordSysID');
inc1.setValue('yourDateField', input.myInput);
inc1.update();
}
})();

 

Works for me when i tested

Mike_R_1-1668796437767.png

 

 

 

View solution in original post

7 REPLIES 7

Mike_R
Kilo Patron
Kilo Patron

If you post the code for your widget, we can take a look

Hi Mike,

Actually, I copied everything same from this link "How to create a Save button in Service portal view... - ServiceNow Community

The difference is that in the widget the input is of type "date" in HTML. 

Try this code

HTML

<sp-date-picker name="mydata" sn-include-time=false field="c.fromDate" ng-model="c.fromDate.value" ></sp-date-picker>
<button class="btn btn-primary" ng-click="UpdateData()">
${Save}
</button>

 

Client

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);
	}
}

 

Server

(function() {

if(input){
var inc1 = new GlideRecord('your_table');
inc1.get('recordSysID');
inc1.setValue('yourDateField', input.myInput);
inc1.update();
}
})();

 

Works for me when i tested

Mike_R_1-1668796437767.png