Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
Coming your way, the Qlik Data Revolution Virtual Summit. October 27-29. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator
Creator

Move Error Files into Seperate Folder

Hi Experts

While moving error files to the destination folder, the following script is moving all files instead of only error files. Can any one trace where i am writing wrong code.

LET vErrorFolderPath='F:\Qlikview\ErrorFolder';

LET vtxtPath='F:\Qlikview\TextFiles';

LET vReloadTimeIn = Now();

SET ErrorMode = 0;

FOR Each vFile in filelist ('$(vtxtPath)\*.txt')

Employee:

LOAD EmpId,

     EmpName,

     Salary

FROM

'$(vFile)'

(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

ErrorLog:

LOAD

'$(vFile)' as FileName,

  '$(vReloadTimeIn)' as [Reload Date and Time],

if(len('$(ScriptError)')=0,'No Error','$(ScriptError)') as Error,

if(len('$(ScriptErrorDetails)')=0,'No Error','$(ScriptErrorDetails)') as ErrorDetails,

'$(#ScriptError)' as ErrorCode

  AutoGenerate 1;

if len($(ScriptError))=1 then

EXECUTE cmd.exe /c MOVE "$(vFile)" "$(vErrorFolderPath)\";

end if

next

SET ErrorMode = 1;

LET vReloadTimeOut = now();

Please find the attached files and application.

Any Suggestions regarding the Scripting Issues.

Best Regards,

Madhu.

1 Solution

Accepted Solutions
Highlighted
Creator III
Creator III

Hi Madhu,

Try this code its working fine.

LET vErrorFolderPath='C:\Users\Ganesh\Desktop\Data\Error Floder';

LET vtxtPath='C:\Users\Ganesh\Desktop\Data';

LET vProcessedFolderPath='C:\Users\Ganesh\Desktop\Data\Processed Folder';

LET vReloadTimeIn = Now();

SET ErrorMode = 0;

FOR Each vFile in filelist ('$(vtxtPath)\*.txt')

Employee:

LOAD EmpId,

    EmpName,

    Salary

FROM

'$(vFile)'

(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

ErrorLog:

LOAD

'$(vFile)' as FileName,

'$(vReloadTimeIn)' as [Reload Date and Time],

if(len('$(ScriptError)')=0,'No Error','$(ScriptError)') as Error,

if(len('$(ScriptErrorDetails)')=0,'No Error','$(ScriptErrorDetails)') as ErrorDetails,

'$(#ScriptError)' as ErrorCode

AutoGenerate 1;

//let vTest=if(FieldIndex('ErrorCode','11'),11,0);

let vpeek=peek('ErrorCode',-1,'ErrorLog');

If $(vpeek) ='0'  then

EXECUTE cmd.exe /C MOVE "$(vFile)" "$(vProcessedFolderPath)\";

ELSE

EXECUTE cmd.exe /C MOVE "$(vFile)" "$(vErrorFolderPath)\";

end if

Let vpeek='';

next

SET ErrorMode = 1;

Best Regards,

Ganesh

View solution in original post

7 Replies
Highlighted
Master II
Master II

Scripterror does not have NULL-values, therefore LEN(ScriptError) will always be 1 (from 0 Errors till 9 Errors).
Suggest to change the script to

if len($(ScriptError))> 0

HTH Peter

Highlighted
Creator
Creator

Thanks for the reply Peter, but no change in the result. 'if len($(ScriptError))> 0' is also moving all files to that folder. Any other suggestions

Best Regards,

Madhu.

Highlighted
Creator
Creator

Hi Experts

can any one suggest me on the above issue

Best Regards

Madhu

Highlighted
Creator
Creator

Hi all

I am struggling to find the condition , that particular  file got Errors.Can any one help to sort this issue.

Example :

if len($(ScriptError))> 0

Thanks

Madhu

Highlighted
Creator III
Creator III

Hi Madhu,

Try this code its working fine.

LET vErrorFolderPath='C:\Users\Ganesh\Desktop\Data\Error Floder';

LET vtxtPath='C:\Users\Ganesh\Desktop\Data';

LET vProcessedFolderPath='C:\Users\Ganesh\Desktop\Data\Processed Folder';

LET vReloadTimeIn = Now();

SET ErrorMode = 0;

FOR Each vFile in filelist ('$(vtxtPath)\*.txt')

Employee:

LOAD EmpId,

    EmpName,

    Salary

FROM

'$(vFile)'

(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

ErrorLog:

LOAD

'$(vFile)' as FileName,

'$(vReloadTimeIn)' as [Reload Date and Time],

if(len('$(ScriptError)')=0,'No Error','$(ScriptError)') as Error,

if(len('$(ScriptErrorDetails)')=0,'No Error','$(ScriptErrorDetails)') as ErrorDetails,

'$(#ScriptError)' as ErrorCode

AutoGenerate 1;

//let vTest=if(FieldIndex('ErrorCode','11'),11,0);

let vpeek=peek('ErrorCode',-1,'ErrorLog');

If $(vpeek) ='0'  then

EXECUTE cmd.exe /C MOVE "$(vFile)" "$(vProcessedFolderPath)\";

ELSE

EXECUTE cmd.exe /C MOVE "$(vFile)" "$(vErrorFolderPath)\";

end if

Let vpeek='';

next

SET ErrorMode = 1;

Best Regards,

Ganesh

View solution in original post

Highlighted
Master II
Master II

Madhu,

just learned from the error-text returned that Scripterror and ScriptErrorDetails etc are no valid functions.

Please use ScriptErrorCount instead in your script - it will always have an integer-value (incl "0")

HTH Peter

Highlighted
Creator
Creator

Hi Ganesh Reddy

Thanks for For your reply, The above script is working fine.

Best Regards

Madhu.