- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 01:07 AM
I'm trying to create a Client Script to calculate age from DoB like picture below
Currently i have no idea to do it lol. I've seen some related posts about that and tried but it's not worked. Pls help me ! Ty
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 01:11 AM
I have replied bro
https://community.servicenow.com/community?id=community_question&sys_id=aae1977edb2a1700fff8a345ca9619e8
Anyways will post it here
Write a script include
var ageScript = Class.create();
ageScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkAge: function() {
var dob = this.getParameter('sysparam_id');//param from client script
var today = new GlideDateTime();
var todayYear = today.getYearLocalTime();
var bday = new GlideDateTime(dob.toString());
var bdayYear = bday.getYearLocalTime();
var age =todayYear - bdayYear;
return age;
},
type: 'ageScript'
});
Then client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ageScript');
ga.addParam('sysparm_name','checkAge');
ga.addParam('sysparam_id',newValue);
ga.getXML(Process);
}
function Process(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var a = parseInt(answer);
alert(a);
g_form.setValue("age",a);
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 07:23 PM
are you getting alert?
check the variable name are correct
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 07:34 PM
Absolutey yes. But it's still not work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 07:37 PM
I have tested the code..it shud work bro
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 07:42 PM
ah ok io got it ! i just change the field name focus on from Age to DoB and it's works

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2018 07:43 PM
cool you figured it out 🙂
Harish