Display info message on field that how many leave balance they have for that selected type?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 09:57 PM
Hi All,
Actually we have record producer to submit a leave request , in that there is field "Leave category"(casual, annual, sick leave), so my requirement was like whenever user select leave type there need display info message on field that how many leave balance they have for that particular selected type
Please help me to achieve this
Thanks
Deepika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 10:37 PM
You need to provide more information such as where is the leave balance stored and how it is stored.
Otherwise, I can only provide a suggestion to use onChange Client Script with AJAX to fetch the data.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 01:38 AM - edited 02-21-2024 02:02 AM
Thanks for the response
Basically leaves stored in Yearly leaves table , here it will like based on the region they have stored the leave with particular category
Yearly leaves table we have leave type filed and reamining leave days , based on that and based on requested for we need fetch the date , but i am not how to write a logic on that
So i need a field message that if particular user select annual leave as a category , then it will show his balance on the field message
Thanks
Deepika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 11:47 AM - edited 02-21-2024 11:49 AM
You can use AJAX for that, create a client callable Script Include. Example below:
var leaveUtil = Class.create();
leaveUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRemainingBalance: function () {
var user = this.getParameter('sysparm_user');
var leaveType = this.getParameter('sysparm_leave_type');
var leaveGr = new GlideRecord(''); //add your table name here
leaveGr.addEncodedQuery('') //add query here, something like subjectPerson = user + leave_type = leaveType
leaveGr.query();
if (leaveGr.next()) {
return leaveGr.getValue('')//add remaining leave days field name
} else {
return;
}
},
type: "leaveUtil"
});
And create an onChange Client Script on the 'Leave Category' field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('leaveUtil');
ga.addParam('sysparm_name', 'getRemainingBalance');
ga.addParam('sysparm_user', '');//add user's sys_id
ga.addParam('sysparm_leave_type', newValue);
ga.getXML(parseResponse);
function parseResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage(gs.getMessage("User's remaining balance is ") + answer);
}
}
You can modify the scripts above to meet your needs.
If you struggle with AJAX, there are plenty of articles/documentation online that can guide you.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 07:33 PM
I have tried like this , but its not working , can you please guide where i am missing
Script include:
var leavebalanceinfo = Class.create();
leavebalanceinfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
leaveinfo: function() {
var type = this.getParameter('sysparm_type');
var user = this.getParameter('sysparm_user');
var leave = new GlideRecord('u_yearly_leave');
leave.addQuery('u_leave_type', type);
leave.addQuery('assigned_to', user);
leave.query();
if (leave.next()) {
return leave.getValue('u_remaining_leave_days');
}
},
type: 'leavebalanceinfo'
});
Catalog Client script
Thanks
Deepika