Autofill of Age based on Date of Birth

Premkumar1
Giga Expert

Hi Friends,

I have a requirement to auto populate the age based on date of birth.I have created a script include and catalog client script for this but the age is not auto populating.while checking the script Include in background script it is working, I think the problem is with client script, can anyone please check and advise us where I am making mistake

Script Include:

var Agescript = Class.create();
Agescript.prototype = {
checkage: function() {
var dob = this.getParameter(sysparam_id);//get data from catalog
var today = new GlideDateTime(gs.nowDateTime());
var todayyear = today.getYearLocalTime();
var bday = new GlideDateTime(dob.tostring());
var bdayyear = bday.getYearLocalTime();
var age = todayyear - bdayyear;
return age;

},

type: 'Agescript'
};

 

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var ga = new GlideAjax('Agescript');
ga.addparam('sysparam_name','checkage');
ga.addParam('sysparam_id',g_form.getValue('dob'));
ga.getXML(Age);
function Age(response){
var ages = response.responseXML.documentElement.getAttribute("Age");
alert("Age is" + ages);
g_form.setValue('age',Age);
}
}

1 ACCEPTED SOLUTION

Hi 

in the below image

in the script below on line 2

Agescript.prototype should be like this. there is a space seen in your line.

I recommend you to create a new client callable Script include .

find_real_file.png

View solution in original post

25 REPLIES 25

Hi Omkar,

Thanks for your reply, As checked it is not working,

can you please provide the client script for this which you tried.

 

Hi 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var ga = new GlideAjax('Agescript');
ga.addParam('sysparm_name','checkage');
ga.addParam('sysparm_id',g_form.getValue('your_field_name'));
ga.getXML(Age);
function Age(response){
var ages = response.responseXML.documentElement.getAttribute("answer");
alert("Age is" + ages);
g_form.setValue('age',Age);
}
}

 

Try this.

 

Mark Correct if it helps.

Warm Regards,

Omkar Mone

find_real_file.png

www.dxsherpa.com

No Luck

Hi 

From the above screenshot

in "g_form.setValue('age',Age);" line your return function name and value that you are passing is same.

g_form.setValue('age',ages);//write this

Go with this.

Mark Correct if it helps.

Warm Regards,

Omkar Mone

find_real_file.png

www.dxsherpa.com

I tried but it is not working.please find the attached screenshots