Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

ramrongala
New Contributor

How exit the script/terminate the QVW while current month file not there in folder

Hi Guys,

Greetings!

Issue:

we have Monthly load in that there are three folders maintained.

For every month one file will be added into that folders,

 
 

But if file is not added in particular month we could not run the job.

so  i am trying to develop automation qvw - if not updated with current month file the qvw file should automatically terminated or failed.

i have already developed the application but if any file not updated it executes entire script.so how to terminate or failed if not updated current month file.

Please find the attached QVW  and do any changes in code

Please help on this.

8 Replies
chrwolf64
Contributor III

Re: How exit the script/terminate the QVW while current month file not there in folder

Try following:

SUB CheckFiles(path)
	FILES:
	LOAD Null() as Name AutoGenerate 0;
	
	FOR Each File in filelist ('$(path)')
		Concatenate(FILES)
		LOAD 
		'$(File)' as Name
		autogenerate 1;
		exit for;
	NEXT File
	
	if NoOfRows('FILES')=0 then
		trace 'No current month file in: $(path)';
		trace 'Script is cancelled!';
		EXIT SCRIPT;
	end if
	
	drop Table FILES;
END SUB

let vCurrentMonthYear = Date(today(),'YYYYMM');

call CheckFiles('c:\New implemnts\Dashboard\Product Dept\PRODUCTION_ORDERS_DATA_$(vCurrentMonthYear)*.csv');
call CheckFiles('c:\New implemnts\Dashboard\Marketing Dept\SALES_ORDERS_DATA_$(vCurrentMonthYear)*.csv');
call CheckFiles('c:\New implemnts\Dashboard\Sales Dept\MARKET_ORDERS_DATA_$(vCurrentMonthYear)*.csv');

trace 'All folders has a current month file.';
trace 'Script is running!';
ramrongala
New Contributor

Re: How exit the script/terminate the QVW while current month file not there in folder

HI ,

Thank you fro your code and guiding but it cant exit/failed while the folders not updated with current month file.

Please share the QVW which u developed, it would be great.

chrwolf64
Contributor III

Re: How exit the script/terminate the QVW while current month file not there in folder

Ok, see attachment.

 

ramrongala
New Contributor

Re: How exit the script/terminate the QVW while current month file not there in folder

Bro, Sales and market folders not having current month files , only product folder having current month file.

in this case the qvw application must exit/failed right but here it execute and not showing anything.

Please help.

  

chrwolf64
Contributor III

Re: How exit the script/terminate the QVW while current month file not there in folder

This is the content of the logfile when I run it in my environment:

2019-11-15 10:40:03 0034 let vCurrentMonthYear = Date(today(),'YYYYMM')
2019-11-15 10:40:03 0036 call CheckFiles('c:\New implemnts\Dashboard\Product Dept\PRODUCTION_ORDERS_DATA_201911*.csv')
  2019-11-15 10:40:03 0014 FILES:
  2019-11-15 10:40:03 0015 	LOAD Null() as Name AutoGenerate 0
  2019-11-15 10:40:03      	1 Felder gefunden: Name, 
  2019-11-15 10:40:03      0 Sätze erhalten
  2019-11-15 10:40:03 0017 FOR Each File in filelist ('c:\New implemnts\Dashboard\Product Dept\PRODUCTION_ORDERS_DATA_201911*.csv')
    2019-11-15 10:40:03 0018 Concatenate(FILES)
    2019-11-15 10:40:03 0019 		LOAD 
    2019-11-15 10:40:03 0020 		'c:\New implemnts\Dashboard\Product Dept\PRODUCTION_ORDERS_DATA_20191112.csv' as Name
    2019-11-15 10:40:03 0021 		autogenerate 1
    2019-11-15 10:40:03      	1 Felder gefunden: Name, 
    2019-11-15 10:40:03      1 Sätze erhalten
  2019-11-15 10:40:03 0022 exit for
  2019-11-15 10:40:03 0025 if NoOfRows('FILES')=0 then
  2019-11-15 10:40:03 0031 drop Table FILES
  2019-11-15 10:40:03 0032 END SUB
2019-11-15 10:40:03 0037 call CheckFiles('c:\New implemnts\Dashboard\Sales Dept\SALES_ORDERS_DATA_201911*.csv')
  2019-11-15 10:40:03 0014 FILES:
  2019-11-15 10:40:03 0015 	LOAD Null() as Name AutoGenerate 0
  2019-11-15 10:40:03      	1 Felder gefunden: Name, 
  2019-11-15 10:40:03      0 Sätze erhalten
  2019-11-15 10:40:03 0017 FOR Each File in filelist ('c:\New implemnts\Dashboard\Sales Dept\SALES_ORDERS_DATA_201911*.csv')
  2019-11-15 10:40:03 0025 if NoOfRows('FILES')=0 then
    2019-11-15 10:40:03 0026 trace 'No current month file in: c:\New implemnts\Dashboard\Sales Dept\SALES_ORDERS_DATA_201911*.csv'
    2019-11-15 10:40:03 0026 'No current month file in: c:\New implemnts\Dashboard\Sales Dept\SALES_ORDERS_DATA_201911*.csv'
    2019-11-15 10:40:03 0027 
    2019-11-15 10:40:03 0027 trace 'Script is cancelled!'
    2019-11-15 10:40:03 0027 'Script is cancelled!'
    2019-11-15 10:40:03 0028 
    2019-11-15 10:40:03 0028 EXIT SCRIPT
  2019-11-15 10:40:03      Ende der Skriptausführung

 

After checking the production folder, everything is Ok. While checking the sales folder, the script aborts.

Support
Support

Re: How exit the script/terminate the QVW while current month file not there in folder

Murthy, not sure what version you are running, but there is such a trigger in the 12.30 and later releases:

https://help.qlik.com/en-US/qlikview/April2019/Subsystems/QMC/Content/QV_QMC/QMC_System_SupportingTa...

Check out the File Exists section.  If you are on an older release, then you will have to use the other logic you have been approaching, but I wanted to let you know there was a new trigger in the later releases just in case.  One trick is to be sure once that file appears, that you then need to move it elsewhere with another task, or the trigger will continue to fire etc...

Regards,
Brett

To help users find verified answers, please don't forget to use the "Accept as Solution" button on any posts that helped you resolve your problem or question.
ramrongala
New Contributor

Re: How exit the script/terminate the QVW while current month file not there in folder

Thank you for your great help, its working fine in my local machine.

My main agenda is  folders not updated with current month data, this qvw won't run in QMC .

we setup triggers like upon success of "folders checking app" then run the mail application(main application.qvw) 

but folder checking app(Source File Checking.qvw )  not failing in qmc but in log file showing script cancelled like below

12/5/2019 4:40:04 PM: 0027      'No current month file in: \\AWSACYIRL12345\Qv\Private\Global\Auxiliar.Files\flat files\Supplier Production\201912_Supplier_Production.txt'

 

12/5/2019 4:40:04 PM: 0028      trace 'Script is cancelled!'

12/5/2019 4:40:04 PM: 0028      'Script is cancelled!'

 

12/5/2019 4:40:04 PM: 0031      EXIT SCRIPT

12/5/2019 4:40:04 PM:      Execution finished 

we put like this in qmc:

main application.qvw -- upon success of  "Source File Checking.qvw" in triggers.

how to fix the issue based on log file message in qmc

Support
Support

Re: How exit the script/terminate the QVW while current month file not there in folder

Really need the full script/document log here to see what is going on prior to the messages you included...  There is no error, it appears the script has built-in logic to cancel/exit if the file is not found, so it appears to me that things are working as expected in this regard...  If the issue is things not failing when you hit this logic and you do NOT want to run the subsequent task, you will likely need to force an error in this case in order to cause the failure.

https://help.qlik.com/en-US/qlikview/April2019/Subsystems/Client/Content/QV_QlikView/Scripting/Error...

That might help in this case, not sure.

Regards,
Brett

To help users find verified answers, please don't forget to use the "Accept as Solution" button on any posts that helped you resolve your problem or question.