Display info message on field that how many leave balance they have for that selected type?

Deepika61
Tera Contributor

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

 

Deepika61_0-1708408649001.png

Please help me to achieve this

Thanks

Deepika

9 REPLIES 9

Hi @Deepika61,

 

Let's try printing some logs to identify where it's going wrong.

 

 

var leavebalanceinfo = Class.create();
leavebalanceinfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    leaveinfo: function () {
        var type = this.getParameter('sysparm_type');
        gs.info("Type of leave is " + type);
        var user = this.getParameter('sysparm_user');
        gs.info("User is " + user);

        var leave = new GlideRecord('u_yearly_leave');
        leave.addQuery('u_leave_type', type);
        leave.addQuery('assigned_to', user);
        leave.query();
        
        gs.info("Query is " + leave.getEncodedQuery());

        if (leave.next()) {

            gs.info("Found leave record " + leave.getDisplayValue());
            gs.info("User's remaining balance is " + leave.getValue('u_remaining_leave_days'));
            return leave.getValue('u_remaining_leave_days');
        }

        gs.info("No record found");

    },
    type: 'leavebalanceinfo'
});

 

 

Update your script include similar to the above and see where the issue is coming from.

 

Thanks 

@James Chun 

 

Actually for the the type its getting some sys_id and for user its getting nothing

Right, so looks like you are using a reference for the type field. You might want to change that to another variable type but be cautious as it can impact other processes.

In regards to the user, you should use the below in your client script

var userId = g_form.getValue('requested_for');

 

@James Chun 

I have used this also , then its also getting sys_id instead of value , now both type and user displaying sys_id ,but i need display value 

You should be getting a sys_id for the name field and a string/text for the type field. So you should change the 'type' variable type to a non-reference field.