How to call a script include from a field style

Dolly M
Tera Guru

Hi all,

 

My requirement is to show color codes in server table based on nearing/expired EOS dates.

 

  • Red color EOS within 3 month (less than or equal to 4 months)
  • Amber color EOS within 6 month (Between 4 to 8 months)
  • Green color EOS in 1 yrs 0r above. (More than 8 months)

I have created a script include but it isn't working. PFB -

 

Script include -

 

var EOSColourCodes = Class.create();
EOSColourCodes.prototype = {
    initialize: function() {},

    redColour: function(current) {
        var server = new GlideRecord('cmdb_ci_server');
        server.addEncodedQuery('operational_statusIN1,9^u_os_eosISNOTEMPTY');
        server.query();
        while (server.next()) {
            var gdt1 = new GlideDate(server.u_os_eos);
            var gdt2 = new GlideDate();
            gdt2.addMonthsUTC(4);
            if (gdt1 <= gdt2) {
                return false;
            } else {
                return true;
            }
        }
    },

    type: 'EOSColourCodes'
};
 
Field style -
DollyM_0-1754457236460.png

 

1 ACCEPTED SOLUTION

Dolly M
Tera Guru

Thanks all,

I was able to get this sorted using Field Styles scripting.

 

DollyM_0-1754460825295.png

 

DollyM_1-1754460847997.png

 

DollyM_3-1754460882634.png

 

 

View solution in original post

8 REPLIES 8

Nikhil Bajaj9
Tera Sage

Hi @Dolly M ,

 

Is your script include is client _callable? If not, please make it and  then check again.

 

Regards,

Nikhil Bajaj

 

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

Yes, it is client callable but not working.

Hi @Dolly M ,

 

Can you try one thing - Uncheck Client callable check box and try again. Then check client callable check box again and check again. let me know your feedback, as code looks correct to me and calling as well.

 

Regards,

Nikhil Bajaj

 

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

I can't get your point. why did you not use variable current in your script include?