Solved: Html type 'date' conversion to Servicenow type 'da... - ServiceNow Community

Html type 'date' conversion to Servicenow type 'date'

AmritaT
Tera Expert

Is there a way to convert the html type 'date' to Servicenow type 'date' ?

Screenshots for reference - 

HTML type -> date : 

find_real_file.png

Servicenow type --> date :

find_real_file.png

 

I'm not able to copy the 'date' from the registration form to the table. Registration form is on the portal.

Any suggestions? Thanks in advance!

 

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

I got what you need. You need some form of handler to display the date when it changes. By default, it displayed (for me) before the date was changed. Client script code that is not in a function gets run on load time. Here is my HTML and Client script as an example. I suspect your main issue was that the field and ng-model attributes didn't match.

<div class="col-sm-6">
  <div class="form-group">
    <label for="date">Inspection Date</label><span id="p3" class="req"></span>
    <sp-date-picker field="data.date" ng-model="data.date" Placeholder="Inspection date" sn-change="dateChanged()"></sp-date-picker>
  </div>
</div>

Client script

function($scope) {
	/* widget controller */
	var c = this;

	$scope.dateChanged = function() {
		console.log('date=' + c.data.date);

	}
}

 

View solution in original post

8 REPLIES 8

Allen Andreas
Administrator
Administrator

Hi,

Can you try:

var date = new GlideDate('u_htmlfieldname');
alert("Date field shows " + date);

This would be for a client script as I'm assuming that's where you're working with this?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
I invite you to visit my ServiceNow focused YouTube channel: Allenovation!

Hi Allen,

 

This is my HTML -

<div class="col-sm-6">
<div class="form-group">
<label for="date">Inspection Date</label><span id="p3" class="req"></span>
<sp-date-picker id="date" name="date" field="date" ng-model="c.data.date" Placeholder="Inspection date"></sp-date-picker>

</div>
</div>

 

Trying to figure out the client part - ???

var idate = document.getElementById('date');
c.data.date = idate;

 

Server Script -

if (input) {

// Initialize GlideRecord
if (input.action == 'Submit') {
// Create template record
var gr = new GlideRecord('mytable');

gr.initialize();
gr.u_date = input.idate;

gr.insert();

}

 

 

If your ng-model is already bound to c.data.date, then your client script already has access to it as c.data.date. There's really nothing to figure out here. You'll get a value like '2019-06-13' in c.data.date. Put in a console.log('date=' + c.data.date); in your client script and observe what happens in the browser's console log.

Hi Chuck - This is what I see in the browser's console log:

find_real_file.png