May 15, 201015 yr I apologize if this has been covered. I searched & didn't find anything. Could have missed it though. Writing our first Custom Function. My background is in C, C#, Java & what not. Logic isn't an issue. We have a 30 Day billing month & I am moving our date diff logic into a single function. No matter what I do, I cannot get the Date Parameters to read in the function correctly. I have tried GetAsNumber for the parameter & GetAsDate in the function. I've tried all sorts of combinations. No luck. I have hard coded the dates, in the function, and it works. Such as Date (5,1,2010). I even hard coded the parameters the same way...and it worked. The fields I am using are defined as dates. I have used GetAsDate on them, with no luck. They even have full 4 digit years. Something is wrong with the data, but here is a copy of the function: Let( [ $dd2 = Date2; $dd1 = Date1 ]; (Year( $dd2 ) * 360 + Month( $dd2 ) * 30 + If( Day( $dd2 ) > 29; 30; Day ( $dd2 ) ) )- (Year( $dd1 ) * 360 + Month( $dd1 ) * 30 + If( Day( $dd1 ) > 29; 30; Day( $dd1 ) ) ) ) Any help is always appreciated.
May 15, 201015 yr "The fields I am using..." Custom functions do not use fields. They take parameters passed to the function. Try posting a simple example file with the function in it.
May 15, 201015 yr Say you create the custom function Add( N1; N2) The function calc is N1 + N2 When you call the function you specify fields or variables to pass to it. In your Invoices table, you could create a field InvoiceTotal, with a calc that uses your custom function: Add( Invoice::subtotal; Invoice::tax )
May 15, 201015 yr Author Thanks Bruce. As soon as I hit the Submit Button, I knew something would pop up. I had two date fields, with very similar names...was using the wrong one. Duh. All good now. If anybody new to date logic needed some 30 Day Billing period logic, at least it is now posted.
May 15, 201015 yr Also there is nom reason to use $variables in the Let function. In fact there are good reasons NOT to use $variables, because their scope can extend outside the CF. It could be changed to: Let( [ dd2 = Date2; dd1 = Date1 ]; (Year( dd2 ) * 360 + Month( dd2 ) * 30 + If( Day( dd2 ) > 29; 30; Day ( dd2 ) ) )- (Year( dd1 ) * 360 + Month( dd1 ) * 30 + If( Day( dd1 ) > 29; 30; Day( dd1 ) ) ) )
May 16, 201015 yr Author Thanks Vaughn. I did know that, but I was otherwise distracted. Now that the dates are correct, I can do without those variables completely. We just converted over from Version 6 a couple weeks ago. Getting up to speed.
May 18, 201015 yr If you have a full version of FMP 6 there was someone looking to buy a copy..... http://fmforums.com/forum/showtopic.php?tid/214687/pid/356112/post/last/m/1/#LAST Just thought I'd pass it along
Create an account or sign in to comment