Please I try to convert string to Date in anyoint studio but I get this error in Avanced rest client "Cannot coerce String (22/03/2012) to Date, caused by: Text '22/03/2012' could not be parsed at index 2.
please can I some one help me .
Thanks advanced .
It looks like you didn't use the right format for the conversion. You need to set the Date format if it is not the default.
Example:
%dw 2.0
output application/java
var inputString="22/03/2012"
---
inputString as Date { format:"dd/MM/yyyy" }
Related
I am trying to check multiple fields on the Choiceset using the Logical AND OR but it is throwing error.Below is the expression I tried
not isEmpty(vars.quoteLineItemId) AND (not isEmpty(payload.PhaseLevelItemNumber) OR not isEmpty(payload.PhaseLevelItemName)
And the error is like Unexpected end of input, expected ')' for the enclosed expression. (line 1, column 124):
I even tried below expression but no luck
vars.quoteLineItemId!=empty AND (payload.PhaseLevelItemNumber!=empty OR payload.PhaseLevelItemName!=empty)
Any help is greatly appreciated
Please make sure to provide sample input and expected output when you ask a question.
Payload
{
"PhaseLevelItemNumber": "Hello world!",
"PhaseLevelItemName": " Hello Mars"
}
Script
%dw 2.0
output application/json
var quoteLineItemId = "asdasdad"
---
not (isEmpty(quoteLineItemId) and ((not isEmpty(payload.PhaseLevelItemNumber) or not isEmpty(payload.PhaseLevelItemName))))
dataroot #("xmlns:od" : "urn:schemas-microsoft-com:officedata" , generated :'date')
What are the possible ways to add current date and time in generated place and dataroot is the root element in my xml.
You can use any expression that returns a formatted date or time instead of the string 'date'.
Example
%dw 2.0
output application/xml
var currentTimeFormated=now() as String {format: "yyyy-MM-dd HH:mm:ss"}
---
dataroot #("xmlns:od" : "urn:schemas-microsoft-com:officedata" , generated: currentTimeFormated) : {}
The formatting patters are the same of the java.time package. You can find more examples at https://docs.mulesoft.com/mule-runtime/4.2/dataweave-types#date_format_change
I'm trying to pacha a string format dated "2019-05-14 13:30:00" to a UNIX format.
In javascript I got it but in the javascript kettle module I am not able to return the numeric value 1557833442
the line of code is this:
const tests = (new Date ("2019-05-14 13:30:00"). getTime () / 1000);
It looks like the Date() constructor doesn't like the format you are using.
If you want the current date, use a Get System Info, it has a number of useful date options.
If you are converting an incoming field, use the Select Values step to change the metadata, using the format string that matches your string field's format.
I get the following error when trying to import a CSV file.
Error Converting '2007/01/02' to type: 'DateTime'. Using the format: 'yyyy/MM/dd'
I have set the class like this:
[FieldConverter(ConverterKind.Date, "yyyy/MM/dd")]
public DateTime PriceDate;
Any idea why that could be, since the format matches - it is the second of Jan 2007?
When I change the date format to 2007.01.02 then Filehelpers parses perfectly.
I use V 3.1.5.0
Thanks
Try changing the mask to:
[FieldConverter(ConverterKind.Date, "yyyy/M/d")]
public DateTime PriceDate;
Click on the 'Converters' tab in this link to learn more about a handful of datatypes available, such as numeric and dates.
I'm using Mule Requester to load a CSV file. After the file is loaded, the payload is a byte array, which I store in a flow variable, mycsv. I keep getting an exception.
org.mule.api.MessagingException: Exception while executing:
NetIds: flowVars.mycsv map $."My Column Name"
^
Cannot coerce a :binary to a :array (com.mulesoft.weave.mule.exception.WeaveExecutionException). Message payload is of type: byte[]
Here's my DataWeave code:
%dw 1.0
%output application/java
---
{
Values: flowVars.mycsv map $."My Column Name"
}
The previous flow element is a choice, so I set the metadata on that to output to a FlowVar with the right name and referenced a sample CSV file, so DataWeave things the variable type is List<Csv>.
How can I read the CSV? Thanks!
It's because it doesnt know the mimeType of the flowVar because it's not set. Try this before the dataweave transformer:
<set-variable value="#[flowVars.mycsv]" variableName="mycsv" mimeType="application/csv" doc:name="Variable" />
or set the mimeType when you first read the csv.
This is the first time I found a requirement to put two different formats into one csv file. In order to get the expected result, I prefer to use this trick:
Create both expressions and combine them into one simple array, using flatten
Add an empty object as line separator