Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

Highlighted
Six Stars

Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

In my tMap component I'm trying to compare two dates, using this code in expression editor:

 

TalendDate.compareDate(parseDate("dd-MM-yyyy","01-01-2000"),row1.CREATEDDATE)

I need to compare the date "01-01-2000" to the date incoming from the dbInputTable row1 and, if equals, do something. Since I can't compare string and dates, I thought about parsing the string first to date and then compare, but when I hit "Test" in the expression builder I have this error:

 

the method parsedate is undefined for the type TalendJavaSourceViewer0

What does this mean? Where am I going wrong?


Accepted Solutions
Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

My code/example runs, no copy paste errors? you probably checked.
Make sure you checked the var compared as "Null / Nullable" (checkbox in tMap)
It will change from int to Integer.

Your error looks like you missing out on some quotes and cant generate your code...

All Replies
Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

TalendDate.parseDate("dd-MM yyyy","01-01-2000")

Thats it. just add TalendDate.

Six Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"


@Dijke wrote:
TalendDate.parseDate("dd-MM yyyy","01-01-2000")

Thats it. just add TalendDate.


I've already tried it but still doesn't work, gives me a generic error (exception in thread main).

Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

in the date format between month and year a '-' is missing:
"dd-MM yyyy","01-01-2000" should be : "dd-MM-yyyy","01-01-2000"
Six Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

Copy-paste error, there is in my code. (I'll modify the post)
Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

I use something different for comparison.

 

// java.util.Date.before(Date when)
// java.util.Date.after(Date when)
// java.util.Date.compareTo(Date when)

TalendDate.parseDate("dd-MM-yyyy","01-01-2000").compareTo(row1.CREATEDDATE)

 

Sidenote: on the TalendJavaSourceViewer ... is it a supported version of java? 

Six Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"


@Dijke wrote:

I use something different for comparison.

 

// java.util.Date.before(Date when)
// java.util.Date.after(Date when)
// java.util.Date.compareTo(Date when)

TalendDate.parseDate("dd-MM-yyyy","01-01-2000").compareTo(row1.CREATEDDATE)

 

Sidenote: on the TalendJavaSourceViewer ... is it a supported version of java? 


I've tried this way doing this:

TalendDate.parseDate("dd-MM-yyyy","01-01-2000").compareTo(row1.CREATEDDATE) == 0 ? TalendDate.parseDate("dd-MM-yyyy","01-01-1900") : row1.CREATEDDATE

But when hitting "test" the same error appears

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

Is there a way to see what this unresolved compilation problem is?

Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

Ok, it might seems strange but... did you restart talend? Sometimes some errors result in some sort of crashing talend (which is eclipse) ... and you keep on running into errors without any particular reason...
This might be the case.

if you select the tMap component (do not open, single click, just select) and on the left lower bottom of this panel (next to view) there's a tab/panel named : code ...
Six Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

I restarted Talend and on the expression builder I have no errors now, but when I try to run the job an error appears saying:

 

object is not an instance of declaring class
Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

It probably has to do with the TalendDate.parseDate().compareTo() which doesnt inherit some util Date stuff I suppose

Try:
in tMap create a var of type Date prsddate which you parse the date
And use in another created var of type int : compareresult
here you: Var.prsddate.compareTo(row1.CREATEDDATE)

Six Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

Like this?

Date prsddate = parseDate("dd-MM-yyyy","01-01-2000");
int compareresult = prssdate.compareTo(row1.CREATEDDATE);
compareresult == 0 ?  parseDate("dd-MM-yyyy","01-01-1900") : row1.CREATEDDATE;

The error is still the same

Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

check screenshot

Six Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

Thanks. And how can I add the if then else condition?

immagine.png

Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

Change your Var datatypes, they are still String ... should be Date and int
And the if in the output should be: Var.compared.equals(0)
Six Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

Did this... is it correct? I need two options for the output

 

immagine.png

Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

Try it like this... screenshot

Do you also want output where date are more recent then your 01-01-1900? 

In the yellow part you add the filter expression, like you did, but just Var.compared>0 .

 

 

 

Six Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

Tried like you showed but it gives me this error:

 

java.lang.IllegalArgumentException: java.lang.ClassCastException@795bb42d
	at sun.reflect.GeneratedMethodAccessor87.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.emf.codegen.jet.JETEmitter.generate(JETEmitter.java:461)
	at org.talend.designer.codegen.config.TalendJetEmitter.generate(TalendJetEmitter.java:684)
	at org.eclipse.emf.codegen.jet.JETEmitter.generate(JETEmitter.java:441)
	at org.eclipse.emf.codegen.jet.JETEmitter.generate(JETEmitter.java:432)
	at org.talend.designer.codegen.proxy.JetProxy.generate(JetProxy.java:54)
	at org.talend.designer.codegen.CodeGenerator.instantiateJetProxy(CodeGenerator.java:446)
	at org.talend.designer.codegen.CodeGenerator.generateContextCode(CodeGenerator.java:363)
	at org.talend.designer.core.runprocess.Processor.updateContextCode(Processor.java:642)
	at org.talend.designer.runprocess.java.JavaProcessor.generateContextCode(JavaProcessor.java:1632)
	at org.talend.designer.runprocess.ProcessorUtilities.generateContextInfo(ProcessorUtilities.java:852)
	at org.talend.designer.runprocess.ProcessorUtilities.generateCode(ProcessorUtilities.java:574)
	at org.talend.designer.runprocess.ProcessorUtilities.generateCode(ProcessorUtilities.java:1736)
	at org.talend.designer.runprocess.RunProcessContext$1.run(RunProcessContext.java:582)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:466)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:374)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:527)
	at org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog.run(ProgressMonitorJobsDialog.java:284)
	at org.eclipse.ui.internal.progress.ProgressManager.run(ProgressManager.java:1190)
	at org.talend.designer.runprocess.RunProcessContext.exec(RunProcessContext.java:534)
	at org.talend.designer.runprocess.remote.RunRemoteProcessContext.exec(RunRemoteProcessContext.java:84)
	at org.talend.designer.runprocess.ui.ProcessComposite.exec(ProcessComposite.java:1401)
	at org.talend.designer.runprocess.ui.views.ProcessView$RunAction.run(ProcessView.java:701)
	at org.talend.designer.runprocess.ui.actions.RunProcessAction.run(RunProcessAction.java:58)
	at org.talend.designer.core.debug.JobLaunchConfigurationDelegate$1.run(JobLaunchConfigurationDelegate.java:84)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4147)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3764)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.talend.rcp.intro.Application.start(Application.java:265)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1465)

What I need to do is to set 01-01-1900 if the date of row1.createddate is equal to prsddate, otherwise I'll set row1.createddate

Ten Stars

Re: Method parsedate does not work - "undefined for the type TalendJavaSourceViewer"

My code/example runs, no copy paste errors? you probably checked.
Make sure you checked the var compared as "Null / Nullable" (checkbox in tMap)
It will change from int to Integer.

Your error looks like you missing out on some quotes and cant generate your code...