Jump to content

Inserting text based upon contents within a field


jdubois

Recommended Posts

I have a situation I need some help with, hopefully I can explain this well enough.

 

I have a field I am calling CreditUnionName. Depending upon the contents of that field I have to return a value of "Member" or "Customer" to be displayed within a paragraph.

 

If CreditUnionName contains the words "Credit Union" or "CU", then I want to return Member. If it contains "Bank" or "Banc", then I want to return Customer.

 

So for example, First National Bank should trigger the return of Customer, because it contains the word Bank.

 

Any help on this would be very much appreciated.

Link to comment
Share on other sites

Create a Text Rule. Insert this code below. Whatever your column header is called in your data file, change Bank Name in this code to it. You can add to the code as well for more changes or requests that come-up.

Check Treat Return Strings as Text.

 

 

if (Field("Bank Name") == "Credit Union")
return "Member";
if (Field("Bank Name") == "CU")
return "Member";
if (Field("Bank Name") == "Bank")
return "Customer";
if (Field("Bank Name") == "Banc")
return "Customer";

else
return Field("Bank Name");

Link to comment
Share on other sites

  • 2 weeks later...

Respectfully, I do not think the code in previous post would work for this situation since the field's contents may include any number of strings with only a portion equaling the word(s) to key off of:

So for example, First National Bank should trigger the return of Customer, because it contains the word Bank.

Instead, I think you would use indexOf() to search the string and determine what text to return. My example uses arrays of search terms so that additional terms can be added if necessary:

// Rule returns either "Customer", "Member", or "" (null) based on contents
// of Field("CreditUnionName"). Note that if contents include words from both
// arrays, "Member" will be returned.

// Additional strings can be added to either array *in lowercase*
var customerKeys = ["banc", "bank"];
var memberKeys = ["credit union", "cu"];
var bankName = Field("CreditUnionName").toLowerCase();
var result = "";

for (var i=0; i<customerKeys.length; i++) {
  if (bankName.indexOf(customerKeys[i]) > -1) {
     result = "Customer";
  }
}

for (var x=0; x<memberKeys.length; x++) {
  if (bankName.indexOf(memberKeys[x]) > -1) {
     result = "Member";
  }
}

return result;

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...