Apigee X timeFormatMs

timeFormatMs() function doesn't work in Apigee X, is there any workarroung?

I'm trying:

<Payload contentType="text/plain">
timeFormatMs: {timeFormatMs('yyyy-MM-dd',system.timestamp)}
</Payload>

 

Solved Solved
0 8 243
1 ACCEPTED SOLUTION

Hmmm... I'm sorry.

I am surprised to report that I looked into the defect database and found b/221768756 (this is an internal reference, not resolvable by you).  Which states that timeFormatMs is failing. Are you using Apigee hybrid?  The bug has been fixed in Apigee X but as of v1.7.0, the fix is not yet released in hybrid. It will be in the next (dot) release of hybrid. 

The workaround is to build the capability yourself in a JavaScript, I suppose. 

 

View solution in original post

8 REPLIES 8

yes try using a placeholder variable for the format, like this:

<AssignMessage name='AM-Set-Payload'>
  <AssignVariable>
    <Name>format1</Name>
    <Value>yyyy-MM-dd</Value>
  </AssignVariable>
  <Set>
    <Payload contentType='text/plain'>
timeFormatMs: {timeFormatMs(format1,system.timestamp)}
</Payload>
   ...

 

Hi dchiesa1

I try this way but I get the same result:

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-Fecha">
    <DisplayName>AM-Fecha</DisplayName>
    <Properties/>
    <AssignVariable>
        <Name>format1</Name>
        <Value>yyyy-MM-dd</Value>
    </AssignVariable>
    <Set>
        <Payload contentType="text/plain">
            timeFormatMs: {timeFormatMs(format1,system.timestamp)}
        </Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="true" transport="http" type="request">flow.dateTime</AssignTo>
</AssignMessage>

The result is:

timeFormatMs:

 

Any other idea?

 

Are you using a current Apigee?  In your policy, why are you creating a new "request" message named "flow.dateTime" ? What is the purpose of that?

This works for me, when I attach the policy in the response flow.  

<AssignMessage name='AM-Response'>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>format1</Name>
    <Value>yyyy-MM-dd</Value>
  </AssignVariable>
  <Set>
    <Payload contentType='application/json'>{
    "timeFormatMs": "{timeFormatMs(format1,system.timestamp)}",
    "status" : "ok"
}
</Payload>
    <ReasonPhrase>OK</ReasonPhrase>
    <StatusCode>200</StatusCode>
  </Set>
  <AssignTo>response</AssignTo>
</AssignMessage>

Result:

{
    "timeFormatMs": "2022-05-11",
    "status" : "ok"
}

 please find attached the working proxy.  Deploy it , then Invoke it with: 

curl -i $endpoint/timeformat/t1 

 

Thanks dchiesa1

I am using Apigee X. I recover flow.dateTime.content in another process.

I deploy the api that you attached to me I get the same result.

ozurita_0-1652288475717.pngozurita_1-1652288534593.png

{
    "timeFormatMs""",
    "status""ok"
}

Any other idea?

Thanks for your quick responses

Any other idea?

Yes. My intuition is that your use of the new variable flow.dateTime is the source of the problem. Without your full API proxy I cannot be sure. But that's where you should look. Try using a separate name for that message. Or try not using that message. If you are only setting content into it, you don't need a full message. You can set a variable.

<AssignMessage name='AM-Formatted-Time'>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>format1</Name>
    <Value>yyyy-MM-dd</Value>
  </AssignVariable>
  <AssignVariable>
    <Name>my-custom-variable</Name>
    <Template>{timeFormatMs(format1,system.timestamp)}</Template>
  </AssignVariable>
</AssignMessage>

The problem is that the timeFormatMs function does not return results.

I am using your proxy and in the debug it is observed that the timeFormatMs function does not return results.

Neither with template.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="AM-Response">
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignVariable>
        <Name>format1</Name>
        <Value>yyyy-MM-dd</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>my-custom-variable</Name>
        <Template>{timeFormatMs(format1,system.timestamp)}</Template>
    </AssignVariable>
    <Set>
        <Payload contentType="application/json">
        {
            "timeFormatMs": "{timeFormatMs(format1,system.timestamp)}",
            "status" : "ok"
        }
        </Payload>
        <ReasonPhrase>OK</ReasonPhrase>
        <StatusCode>200</StatusCode>
    </Set>
    <AssignTo>response</AssignTo>
</AssignMessage>

ozurita_1-1652291609933.png

Thanks.

Hmmm... I'm sorry.

I am surprised to report that I looked into the defect database and found b/221768756 (this is an internal reference, not resolvable by you).  Which states that timeFormatMs is failing. Are you using Apigee hybrid?  The bug has been fixed in Apigee X but as of v1.7.0, the fix is not yet released in hybrid. It will be in the next (dot) release of hybrid. 

The workaround is to build the capability yourself in a JavaScript, I suppose. 

 

My administrator hasn't shared the Apigee X version data with me. But it's almost certainly the version of the bug.

Thank you very much.