Pass GlideRecord object to function

Volker1
Kilo Contributor

Hi everyone,

 

I cannot pass a GlideRecord object to a function in a Script include. Is this normale/ intended behaviour?

When I pass the GlideRecord to the object, I can still read the field names using GlideRecordUtil, but the row count is zero and I also cannot read any real values from records inside my function.

This is what i wrote:

  translateGlideRecordToArray: function(glideRecord){

        var isGlideRecord;
        var glideRecordFields;
        var gru = new GlideRecordUtil();
        var fields = [];

        // check whether given glideRecord is a GlideRecord instance
        isGlideRecord = glideRecord instanceof GlideRecord;
        if (isGlideRecord){
            
            // go to first entry of glideRecord
            glideRecord.get();
            // get field names from gliderecord
            fields = gru.getFields(glideRecord);
            gs.info("field names of current GlideRecord: " + fields);
 
            gs.info(glideRecord.getRowCount()); // zero
            gs.info(glideRecord.sys_id); // undefined

            // go before the first entry of the gliderecord
            glideRecord.restoreLocation();
            gs.info(glideRecord.getRowCount()); // still zero

            while(glideRecord.next()){

                gs.info(glideRecord.sys_id); // nothing happens here

            }
            gs.info("end of records!");


2 REPLIES 2

Chaitanya Redd5
Tera Guru

Hi,

Could you please post your complete script or the function where you are facing issues and also the functionality which you want to achieve so that it will be easy for us to debug the issue.

Also, GlideRecord object can be passed to function please find below the link for reference.

https://community.servicenow.com/community?id=community_question&sys_id=a4ef7eaddb58dbc01dcaf3231f96...

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Chaitanya

Volker1
Kilo Contributor

I solved it! I can post the solution later. Thanks anyway! 🙂