Jump to content

Return no value when only a first initial is present?


-Lisa-

Recommended Posts

Hi everyone,

 

I've been running into this a lot lately....

 

I have several customers that call out to a recipient's first name on their VDP pieces. Many of these customers have mailing lists which consist of records that have only a first initial instead of a full name. I'd like to be able to return no value in these instances and I'm at a loss as to how to get JavaScript to determine whether there is a full name or only one initial in a given record. :confused:

 

Anyone have any suggestions?

 

Thanks in advance!!

Link to comment
Share on other sites

Hi Dan,

 

No, the first initial is part of the original FirstName field. For instance, here is a sample of four records:

 

FirstName LastName

John Smith

M Jones

Joe Martin

L Miller

 

I need to be able to write a rule which will determine which records have only a first initial as opposed to a full name and return a null value.

 

Thanks!

Link to comment
Share on other sites

Hi Dan,

 

No, the first initial is part of the original FirstName field. For instance, here is a sample of four records:

 

FirstName LastName

John Smith

M Jones

Joe Martin

L Miller

 

I need to be able to write a rule which will determine which records have only a first initial as opposed to a full name and return a null value.

 

Thanks!

 

I don't know if an actual Null value is what you want; an empty string would probably be better. If it's always either a single initial or a full name you could use something along the lines of this:

 

return (Field("FirstName").length==1) ? "" : Field("FirstName");

Link to comment
Share on other sites

I don't know if an actual Null value is what you want; an empty string would probably be better. If it's always either a single initial or a full name you could use something along the lines of this:

 

return (Field("FirstName").length==1) ? "" : Field("FirstName");

 

I think this is close to what I'm looking for, thanks! I tried entering it exactly as entered but I'm receiving a syntax error. Also, I want to add a line where if the First Name field is empty, it also returns an empty string. Normally I can compose this into a rule with no problem but I'm not sure how to include it in the code above.....

Link to comment
Share on other sites

I think this is close to what I'm looking for, thanks! I tried entering it exactly as entered but I'm receiving a syntax error. Also, I want to add a line where if the First Name field is empty, it also returns an empty string. Normally I can compose this into a rule with no problem but I'm not sure how to include it in the code above.....

 

You could just change your comparison to accommodate an empty string:

return (Field("FirstName").length<=1) ? "" : Field("FirstName");

 

What is the error you are getting? Maybe your field isn't called FirstName?

Link to comment
Share on other sites

 

What is the error you are getting? Maybe your field isn't called FirstName?

 

I changed the name of my field to correspond with my datafile so that wasn't it. I wasn't really familiar with the format you provided for the rule so I tried using your components to build a JS rule I was more familiar with. I think that's probably why it wasn't working. Once I copied and pasted the new code you provided adding a provision for an empty string, it worked!

 

Thank you so much for helping me through this!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...