- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 07:50 PM
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);
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 11:44 PM
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 .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2018 02:07 AM
here you go.
Script include :
var check = Class.create();
check.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkage: function() {
var dob = this.getParameter('sysparm_user_name');//get data from catalog
var datebirth = gs.dateDiff(dob,gs.nowDate(), true);
gs.log('Difference: '+datebirth);
var seconds = parseInt(datebirth, 10);
var whole = seconds/(365*24*3600);
var convert = Math.floor(whole);
gs.log('Years: '+convert);
return convert;
},
type: 'check'
});
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var db = g_form.getValue('u_dob');
var ga = new GlideAjax('check');
ga.addParam('sysparm_name', 'checkage');
ga.addParam('sysparm_user_name', db);
ga.getXML(HelloWorldParse);
}
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
I tested and it worked for me.
Note: i would suggest you to create new script include and new client script because the above script include you had created is not client callable because they have different prototype .