Page 1 of 1

Calendar Status and Operators

PostPosted: Tue May 04, 2010 3:33 pm
by sws-solutions
If you try to use operators within the status text, the colour coding will fail.

This is because the colours are written to a variable, a variable name cannot contain any operators.

For example :

A or B
C and D
A & B

I only came to realise this after a few of our users reported a lot of black colours, after looking closer, I realised they where using status like

Off / Holiday and MOT / Service

So after a little bit of 'experimenting' here is a solution.
I have tried to write it using a newer calendar version, but it may not be 100% correct since I use my own colour coding implementation...

Basically, the idea is to strip out any operators before creating the variables and also before creating the arrays used by the calendar
So, A & B becomes AB or Yes AND No becomes YesNo


Script : Load Source Colors (or Apply Color Settings in new versions)

Change the code to substitute out these operators, before building the evaluate string

Code: Select all

Let (

NewStatus = Substitute ( CalendarColors::Name ;
[" and " ; ""] ;
[" or " ; ""] ;
[" & " ; ""] ;
etc .....
[" not " ; ""]
) ;

Evaluate ( "Let ($$sc_Color" & NewStatus & " = " & CalendarColors::ColorRGBValue & " ; \"\")")

)




Then in Write One Filemaker Event in iCal Format, edit the line which gets the status

Code: Select all

Set Variable [$scical_Status; Value: Substitute ( GetField ($$sc_FieldForStatus) ; [" and " ; ""] ; [" or " ; ""] etc etc etc  ) ]



As mentioned above, I have modified my own integration which may differ from later versions of SeedCode Calendar, so it may need adapting to work in the current version. But the principle should be the same.

PostPosted: Tue May 04, 2010 3:55 pm
by John Sindelar
Hey Steve,

Good timing. I've been working on this also as a customer had statuses with math operators in them:

Partial 3/4
Hold - Us
Parts+

Came up with a low impact solution that uses Code() to transform the status name into a number:

1. Edit the script "Apply Color Settings { Close , Dont Refresh }" and find the Set Variable step in our loop. Wrap the color name in the Code function so it looks like this:

Evaluate ( "Let ( $$sc_Color" & Code( CalendarColors::Name ) &" = " & CalendarColors::ColorRBGValue & " ; \"\" )" )

2. Edit the script "Write One FileMaker Event in iCal Format" and find where we set the variable $scical_Status. Wrap that as well so it looks like this: Code ( GetField ( $$sc_FieldForStatus ) )

I think we'll add this in the next build, but I'm still testing it. Variable names can only be 100 characters long, so this could fail if you had status names over 45 characters long.

PostPosted: Tue May 04, 2010 4:03 pm
by sws-solutions
:wink:

Im sure that will run a lot faster, especially on a full calendar...
Now why didn't I think of that..

Limiting the status name is not an issue for me, Ill implement it now and give it some testing...

Thanks

PostPosted: Tue May 04, 2010 4:12 pm
by John Sindelar
That would be cool Steve; thanks!

PostPosted: Tue May 04, 2010 4:35 pm
by sws-solutions
Dont forget to edit z_sc_ColorCalc in the events table if you use it

Let ( [

s = code(status)

// above is the field you're using to color code events.......

P.S Seems to be working quite well, I had quite a few test statuses... sure beats a long string of substitutions.

(statuses hmm.. is that the way its written)

PostPosted: Thu Jun 24, 2010 12:16 pm
by hedrich
I've got the same issue here and I've followed the guidance for using the Code() function as outlined on this thread. Those changes fixed the problem when I used a status value with the operator "Not" in it, but it still breaks with the operator "Or". Very odd. The exact text that still breaks color coding for me is "Open New or Current".

PostPosted: Thu Jun 24, 2010 12:28 pm
by John Sindelar
Hi, it's not the "or", it's the length. Using this code() mod your statuses can't be too long. Yours is 1 character too long: you'll find that "Open New or Curren" works.

Hope that helps,

John

PostPosted: Thu Jun 24, 2010 12:47 pm
by hedrich
Aha! Well, this is the first time I've used Code()...

I'd already solved it by changing the status value to "Open New/Current", which works just fine and now I know why.

Thanks! I've learned something new today...

PostPosted: Thu Jul 22, 2010 5:46 pm
by John Sindelar
Code() is a cool, quick fix for this, but it has limitation as to how long a string it can encode into a variable name. A more through fix is to add a custom function to your solution. Call this "SeedCode_NoOperators" and define it like this:

Code: Select all
/*

SeedCode_NoOperators ( string )

Removes operators from fields we want to use as variable names

*/

Substitute ( string ;
["\"" ; "" ] ;
["(" ; "" ] ;
[")" ; "" ] ;
["+" ; "" ] ;
["-" ; "" ] ;
[">" ; "" ] ;
["<" ; "" ] ;
["=" ; "" ] ;
["≠" ; "" ] ;
["≤" ; "" ] ;
["≥" ; "" ] ;
["&" ; "" ] ;
["^" ; "" ] ;
["/" ; "" ] ;
["*" ; "" ] ;
[" or " ; "" ] ;
[" and " ; "" ] ;
[" not " ; "" ] ;
[" xor " ; "" ]
)


Now use "SeedCodeNoOperators(" in place of "Code(" in the modifications above.

PostPosted: Fri Jul 23, 2010 1:17 pm
by hedrich
I like that! Will do it now....

PostPosted: Fri Jul 23, 2010 2:01 pm
by hedrich
Caveat with this custom function that I found right off...

If the string is, e.g., "Do Not Schedule", the CF doesn't work because the Substitute function is Case sensitive. To be safe you might want to revise the CF to wrap Lower () around "string".

Code: Select all
/*

SeedCode_NoOperators ( string )

Removes operators from fields we want to use as variable names

*/

Substitute ( Lower ( string ) ;
["\"" ; "" ] ;
["(" ; "" ] ;
[")" ; "" ] ;
["+" ; "" ] ;
["-" ; "" ] ;
[">" ; "" ] ;
["<" ; "" ] ;
["=" ; "" ] ;
["≠" ; "" ] ;
["≤" ; "" ] ;
["≥" ; "" ] ;
["&" ; "" ] ;
["^" ; "" ] ;
["/" ; "" ] ;
["*" ; "" ] ;
[" or " ; "" ] ;
[" and " ; "" ] ;
[" not " ; "" ] ;
[" xor " ; "" ]
)

PostPosted: Fri Jul 23, 2010 2:32 pm
by John Sindelar
Nicely done!

Bump (colors displaying as black with operators present)

PostPosted: Fri Sep 24, 2010 2:42 pm
by Jonathan
I just wanted to say that this thread solved the problem for me. Client wants to Categorize events like Class (Public) and Class ( Contract ), and those parens resulted in black. I didn't find this thread the first time I searched, but in the end the Custom Function (including the Lower () function) worked like a charm.

John, you'll save some users a headache if you can include this mod in your solution.

Thanks for a great calendar,
-jb

PostPosted: Thu Nov 11, 2010 8:29 am
by John Sindelar
Thanks jb. We have added this to the latest builds of Pro and Complete and it is making things a lot easier. We did omit a few operators though, so folks are adding commas and semicolons into the function if they want to use those in their statuses.

Best,

John