The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Differences between glide objects and their field counterparts.

raprohaska
Kilo Guru

My specific example is the difference between a GlideDuration object and Duration field, though there are also differences between GlideDateTime and date/time fields... and I'm betting there are more.

In my main example, I utilize the "dateNumericValue" function available on a duration field in a generic method to calculate a target date based on a start date, duration, and schedule. I built the function so that any duration could be passed in as a parameter, thinking that it wouldn't matter if the consumer passes in a GlideDuration object or a duration value of a record's duration field (for example catalog item's delivery time field).

The problem is that dateNumericValue is not available on a GlideDuration object. My question is, is there a way to create a duration in the same manner that ServiceNow creates the value within a Duration field instead of "new GlideDuration()"?

Which then leads to a general question, can we create variables of other field types as well, so that I can build general functionality and not worry how the object is created (from the database or "new" object in script)?

find_real_file.png

3 REPLIES 3

danpatino
Tera Expert

Hi Aaron,



Try just 'numericValue' as a property.



gs.log(duration.numericValue);



You may have to define a new GlideDuration object since pulling it directly from a glide record will give you a glide element instead.



gd = new GlideDuration(duration);


gs.log(gd.numericValue);


danpatino
Tera Expert

Hi Aaron,   Did this approach work out for you?


I haven't had a chance to try it out. It will take a new calculation as I think the duration formats would be different, seconds to days or something along those lines. It is a worthy answer to a work around for sure. I just wonder why ServiceNow creates a data type that exposes different functionality from its glide counterpart. These inconsistencies make the tool feel clunky to folks that have developed in other development environments.



I will post if it worked once I get a moment to go back to that challenge. As of now I hacked it to use the glide records datetime field instead, per the posted code. What is really funny is, I opened a ServiceNow HI ticket asking the same thing and they said that my solution was creative and not a hack, LOL.



Thanks for the response,


AA