Jump to content

Format Phone to Code


AngelBenitez

Recommended Posts

Hello,

I am trying to create a rule that would include the Choose Phone Format option with all dots (123.456.7890) to the code below.

if (Field("ChoosePhone") == "Direct" && Field("Direct") != "")
{
   return Field("Direct");
}
else if (Field("ChoosePhone") == "Mobile" && Field("Mobile") != "")
{
   return Field("Mobile");
}
else if (Field("ChoosePhone") == "Center" && Field("CenterPhoneNumber") != "")
{
   return Field("CenterPhoneNumber");
}
else
{
    return Field("Direct");
}

Does anyone know how I would go about this?

Link to comment
Share on other sites

If you're in FP 11 or later, then the code you have in that JavaScript rule is fine, and you don't need to make any changes at all to it.  What you need to do is create a new rule, select the "Choose Phone Format" Form Rule, select the name of your JavaScript rule in the "choose field" drop-down list, then select your format.  Then use that form rule in your text frame, and it will format the phone number selected by your script logic.

  • Like 1
Link to comment
Share on other sites

10 hours ago, AngelBenitez said:

Hello @Dan Korn; that's what I want to avoid. I don't want to create a rule to depend on another rule. I only want one rule in the rules to achieve the same result.

Is this possible to do?

I don't understand your aversion to nested rules, but I suppose if you want to do this all in one rule, then you could just create the "Choose Phone Format" rule with the desired formatting, then convert it to JavaScript, and add any other logic you want.

  • Like 1
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...