Jump to content

Empty field and extra spaces


Tattoued

Recommended Posts

This is probably in the forum somewhere, but I cannot find it at the moment and have already spent WAY more time than I should to compose this job!

 

Mac version FusionPro Desktop 7.2P1k

 

I have the following fields: Salutation, First Name, Middle Name, Last Name, Suffix.

 

There are records that have none of the above, so I have created a rule that says if no name, replace with Valued Customer. I added a field to the csv file to that effect, so that I could create a simple rule. I also need to eliminate any extra spaces that might appear if there is no suffix, and also if there is no middle name, since some of the records have first and last but no middle. I'm have a HECK of a time making EVERYTHING work. I can get the first middle last to behave, but then when I come across a first and last only, I get an extra space for the middle. If I take out the space in the rule, then it smashes everything together. HELP, please!!! Here's the formula:

 

if (Field("First Name") == "") {

return Field("If no name")}

else

return Field("First Name")+" "+Field("Middle Name")+" "+Field("Last Name")

}

if Field("Middle Name") =="")

return Field("First Name")+" "+Field("Last Name")

Link to comment
Share on other sites

You just have the sequence a little messed up. Try this:

 

if (Field("First Name") == "")
return Field("If no name");
else if (Field("Middle Name") == "")
return Field("First Name")+" "+Field("Last Name");
else
return Field("First Name")+" "+Field("Middle Name")+" "+Field("Last Name");

 

There are better ways to error proof this but this should at least work.

Link to comment
Share on other sites

That worked AWESOME except that I don't think I can use my suffix rule, and I'm not getting the space between the last name and the suffix... where do I put that? I tried tacking it onto the end of what you gave me, including the additional space, and it's ignoring me.
Link to comment
Share on other sites

It's hard to see what you mean without seeing the script you have. I would replace the whole thing with this:

 

var NoName = Field("If no name");
var FName = Field("First Name");
var MName = Field("Middle Name");
var LName = Field("Last Name");
var Suffix = Field("Suffix");
var sp = " ";

if (FName.length > 0)
{
FName += sp;
if (MName.length > 0) MName += sp;
if (Suffix.length > 0) LName += "," + sp + Suffix;

return FName + MName + LName;
}
else
{
return NoName;
}

 

It sets up a variable for each field then appends spaces or the suffix if needed.

Link to comment
Share on other sites

Beautiful! That worked! Thank you so much for saving my sanity! I knew I was on the right track, but I didn't know if I was setting it up in the right order or not, or what I was doing wrong. Code is way over my head sometimes...

 

Thank you so much!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...