How do you pass an object to a function in a script include

bdshan
Tera Expert

I have the following function in a script include:

glideDateTimeToISO: function(glideDateTime) {
        var isoDate = new Date(glideDateTime.getNumericValue()).toISOString();
        return isoDate;
    }

It takes in a GlideDateTime object. Problem is when I call the function from a business rule with:

var isoTimeDate = myUtils.glideDateTimeToISO((gr.event_datetime));

where gr.event_datetime is a DateTime field, I get the following error:

"TypeError: Cannot find function getNumericValue in object 2023-08-04 04:00:00."

 

How do you pass an object from a business rule to a script include?

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, I think your issue is the way you are attempting to utilize the GlideDateTime methods.
testing in an OOB PDI background window I think something like will work.

function glideDateTimeToISO(myTime) {
    var gdt = new GlideDateTime(myTime);
        var isoDate = new Date(gdt.getNumericValue()).toISOString();
        return isoDate;
    }
     
var test = new GlideRecord('incident');
test.get('57af7aec73d423002728660c4cf6a71c');

var isoTimeDate = glideDateTimeToISO(test.opened_at);
gs.info('isoTimeDate ' + isoTimeDate);

 

View solution in original post

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, I think your issue is the way you are attempting to utilize the GlideDateTime methods.
testing in an OOB PDI background window I think something like will work.

function glideDateTimeToISO(myTime) {
    var gdt = new GlideDateTime(myTime);
        var isoDate = new Date(gdt.getNumericValue()).toISOString();
        return isoDate;
    }
     
var test = new GlideRecord('incident');
test.get('57af7aec73d423002728660c4cf6a71c');

var isoTimeDate = glideDateTimeToISO(test.opened_at);
gs.info('isoTimeDate ' + isoTimeDate);