You are viewing limited content. For full access, please sign in.

Question

Question

Search for each month

asked on November 8, 2018

Hi!

 

I'm using a Workflow to know how many folders I have for each month.

For that, I created a loop for each month (1 to 12) ; inside this loop I'm using the search syntax.

{LF:Name="FileName", Type="F"} & {LF:Created>="1/M/YYYY", Created<="31/M/YYYY"}

This syntax is not pretty good because some month doesn't have 31 days and the search return an error.

 

I can't put Created<="30/M/YYYY" because some folders are created the 31.

And sometimes, febuary have 28 or 29 days.

 

I tried this too but unsucess.

{LF:Name="FileName", Type="F"} & {LF:Created="*/M/YYYY"}

 

I tried the next one too, but for december, I'll get a bug because the month 13 doesn't exist.

{LF:Name="FileName", Type="F"} & {LF:Created>="1/M/YYYY", Created<"1/M+1/YYYY"}

 

How can I do?

 

Thanks in advance.

Regards

0 0

Answer

SELECTED ANSWER
replied on November 9, 2018

You could do this easily in a script activity.

var year = 2018; //get from token
var startMonth = 1; //start with january, or pass in the desired start month with a token
var endMonth = 12; //end with december, or pass in the desired end month with a token

while (startMonth <= endMonth)
{
	var startDateString = new DateTime(year, startMonth, 1).ToString("d/M/yyyy");
	var endDateString = new DateTime(year, startMonth, DateTime.DaysInMonth(year, startMonth)).ToString("d/M/yyyy");
	
	var searchString = @"{LF:Name=""FileName"", Type=""F""} & {LF:Created>=""" + startDateString + @", Created<=""" + endDateString + @"""}";
	
	//Then do whatever search you want and return only the statistics.
}

You can also use Workflow activities to do the looping, and generate each search string individually.

var year = 2018; //get from token
var month = 1; //get from token
var startDateString = new DateTime(year, month, 1).ToString("d/M/yyyy");
var endDateString = new DateTime(year, month, DateTime.DaysInMonth(year, month)).ToString("d/M/yyyy");

var searchString = @"{LF:Name=""FileName"", Type=""F""} & {LF:Created>=""" + startDateString + @", Created<=""" + endDateString + @"""}";

 

1 0
replied on November 9, 2018

Hi Devin,

 

Thank you for your help. This is a great idea!

Regards

0 0
replied on November 9, 2018

In workflow, you can also use the Date Token Calculator

2 0
replied on November 12, 2018

Yes you right Bert! I didn't think about that! XD

0 0
replied on November 13, 2018 Show version history

:facepalm:

Next up on stupid developer tricks: Spending a day writing a script to automate 10 minutes of work.

Ignore me, I'm dumb.

0 0
replied on November 13, 2018

laugh But it was great code!

I have been there and done that... forget about a built in function/feature and reinvent the wheel.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.