PDA

View Full Version : OnRecordStart rule TypeError:Field("RegTypeB").toTitleCase is not a function


dwhetzel
October 26th, 2012, 09:01 AM
Spent the better part of the day trying to figure this out. Searched and searched the forums still stumped. If I comment out the line with "toTitleCase" in it validation passes and it works fine.
I've tried all kinds of variations on the name to no avail.

Error when validating scrpt... In an OnRecordStart rule.
TypeError:Field("RegTypeB").toTitleCase is not a function

Thanks so much for any help with this it's driving me crazy. (short drive that it is):D



[CODE]if (Field("RegTypeB") == "Government for the people")
{
// statements to perform if
// expression is true
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toUpperCase());
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toLowerCase());
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toTitleCase());
var botBar = FindTextFrame("botBar");
botBar.suppress = false;
}
else if (Field("RegTypeB") == "Sponsor")
{
// statements to perform if
// expression is true
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toUpperCase());
var botBar = FindTextFrame("botBar");
botBar.suppress = false;
}
else if (Field("RegTypeB") == "Staff")
{
// statements to perform if
// expression is true
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toUpperCase());
var botBar = FindTextFrame("botBar");
botBar.suppress = false;
}
else if (Field("RegTypeB") == "Press")
{
// statements to perform if
// expression is true
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toUpperCase());
var botBar = FindTextFrame("botBar");
botBar.suppress = false;
}
else if (Field("RegTypeB") == "Industry")
{
// statements to perform if
// expression is true
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toUpperCase());
var botBar = FindTextFrame("botBar");
botBar.suppress = true;
}
else
{
// statements to perform if
// none of the above expressions is true
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toUpperCase());
var botBar = FindTextFrame("botBar");
botBar.suppress = true;
}

Dan Korn
October 26th, 2012, 09:15 AM
The message is correct; toTitleCase is not a method of the String object (https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/prototype#Methods). However, there is a global function named ToTitleCase, which is part of FusionPro. So you want to do this:
FusionPro.Composition.AddVariable("RegTypeB", ToTitleCase(Field("RegTypeB")));Also, why do you have three lines like this in a row?
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toUpperCase());
FusionPro.Composition.AddVariable("RegTypeB", Field("RegTypeB").toLowerCase());
FusionPro.Composition.AddVariable("RegTypeB", ToTitleCase(Field("RegTypeB")));Only the last one is going to have any effect.

It seems that the logic in your rule can be reduced to this:
var RegTypeB = Field("RegTypeB");
FusionPro.Composition.AddVariable("RegTypeB", RegTypeB.toUpperCase());
switch (RegTypeB)
{
case "Government for the people":
FusionPro.Composition.AddVariable("RegTypeB", ToTitleCase(RegTypeB));

case "Sponsor":
case "Staff":
case "Press":
break;

default:
FindTextFrame("botBar").suppress = true;
}

dwhetzel
October 26th, 2012, 09:38 AM
Thanks Dan!
That line worked like a charm of course you already knew that.
I will work on incorporating your reduced code into my rule instead.

Have a great weekend!