Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Apigee X JavaScript Math Object

Hi @kurtkanaskie 

If there was a thread already, please do point me there for the query. Does the JavaScript Math Object support Long, type. While executing the proxy I see the following error:

{
    "fault": {
        "faultstring": "Execution of JS-CalculateExpiryTime failed with error: Javascript runtime error: \"TypeError: Cannot find function Long in object [object Math]. (calculateTimeStamp.js:5)\"",
        "detail": {
            "errorcode": "steps.javascript.ScriptExecutionFailed"
        }
    }
}
I am trying to achieve something like this :

 

var currentTime = Math.floor(+new Date()); // the current time in milliseconds
var issuedAtTimeSeconds = Long.valueOf(currentTime/1000);

 

 Thanks,
Debjit
Solved Solved
4 4 405
1 ACCEPTED SOLUTION

Thanks @dchiesa1 , I used the Math round function to achieve this and was able to get the value rounded off, I do have one last question, I am trying this 

 

var currentTimeStamp = context.getVariable("system.timestamp");
print("The current time is "+currentTimeStamp);
var issuedAtTime = Math.round(currentTimeStamp/1000);
print("The issued time is "+issuedAtTime);
var timeToExpire = 300;
var expirationTime = issuedAtTime+timeToExpire;
print("The expiration time is "+expirationTime);
var expTime = context.setVariable("expTime", context.getVariable("expirationTime"));
print("The exp time is "+expTime);

 

I printed the values to check if its getting values correctly to each variable, but the value for expTime is evaluating to undefined, I am seeing the GET to expirationTime is empty which I am sure is cause for the value of expTime to be showing as undefined, but am unable to figure out the issue. Please let me know if am missing out something, excerpt from the trace below:

The current time is 1719255765674 The issued time is 1719255766 The expiration time is 1719256066 The exp time is undefined

expTimeValue.PNG

I intend to use the value of expTime downstream within the proxy, by referencing to this variable.

Thanks,

Debjit

View solution in original post

4 REPLIES 4