Jump to content

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


dwhetzel

Recommended Posts

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

 

 

 

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;

}

Link to comment
Share on other sites

The message is correct; toTitleCase is not a method of the String object. 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;
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...