Jump to content

External file, suppress if empty


mdlivels

Recommended Posts

Hi-

I'm using an external data file to pull in multi-line records for a provider directory, sorted by specialty. All of that is fine, except when there's a field that ins't populated (like address3). I cannot figure out how to collapse empty fields like I normally would using this method. So most of the entries do NOT have anything in address3, but I've got tons of awkward empty spaces and need to solve this. Here's the code;

 

var result = "";

 

Provider = new ExternalDataFileEx("providers.xlsx", "Excel", "providers");

XDFList = Provider.SortBy("SPECIALTY");

var rows = XDFList.FindRecords("Adult Companion");

 

var content_fields = ["last_name","address1","address2","address3","city","state","zip","phone","hours","URL"];

 

for (row in rows) {

 

for (i = 0; i < content_fields.length; i++) {

 

if (content_fields != '') {

 

if (content_fields == 'last_name') {

result += "<b/><color name=black>" + Provider.GetFieldValue(row, content_fields)+ "</b><br>";

} else if (content_fields == 'address1') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}else if (content_fields == 'address2') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}else if (content_fields == 'address3') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}else if (content_fields == 'city') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ ", ";

} else if (content_fields == 'state') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ " ";

}else if (content_fields == 'zip') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}else if (content_fields == 'phone') {

result += "<color name=black>" + "Phone/Telefono: " + Provider.GetFieldValue(row, content_fields)+ " <br>";

}else if (content_fields == 'hours') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ ", ";

}else if (content_fields == 'URL') {

result += "<color name=black>" + "URL: " + Provider.GetFieldValue(row, content_fields)+ "<br>";

} else {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}

 

}

 

}

 

result += "<br><p>";

 

}

 

return result;

 

FusionPro Creator 10.0.3 and producer server (PC/Mac/Server)

Link to comment
Share on other sites

You could try something like this to form the address block:

 

CityStateZip = [[Field("City"),Field("State")].filter(String).join(" "),Field("Zip")].filter(String).join("  ");
myFullName = [Field("First Name"),Field("Last Name")].filter(String).join(" ");
return [myFullName,Field("Company"),Field("Mailing Address Line 1"),Field("Mailing Address Line 2"),CityStateZip].filter(String).join("\n").toUpperCase();

 

If one of the fields is blank, it is removed from the array by the filter.

Link to comment
Share on other sites

This is what ended up working, just FYI. Thanks for the help - it didn't work specifically as you gave it to me for my purpose, but you sent me down the right path.

 

var result = "";

 

Provider = new ExternalDataFileEx("providers.xlsx", "Excel", "providers");

//XDFList = Provider.SortBy("SPECIALTY");

var rows = XDFList.FindRecords("Adult Companion");

 

// Create an arry of all the content fields you need to check

var content_fields = ["last_name","address1","address2","address3","city","state","zip","phone","hours","URL"];

 

/**/

for (row in rows) {

 

result += "<p>";

 

//if (row.length != 0) {

// loop through each value of content_fields array

for (i = 0; i < content_fields.length; i++) {

 

// check to make sure there is a value for the content field

if (Provider.GetFieldValue(row, content_fields) != '') {

 

if (content_fields == 'last_name') {

result += "<b/><color name=black>" + Provider.GetFieldValue(row, content_fields)+ "</b><br>";

} else if (content_fields == 'address1') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}else if (content_fields == 'address2') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}else if (content_fields == 'address3') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}else if (content_fields == 'city') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ ", ";

} else if (content_fields == 'state') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ " ";

}else if (content_fields == 'zip') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}else if (content_fields == 'phone') {

result += "<color name=black>" + "Phone/Telefono: " + Provider.GetFieldValue(row, content_fields)+ " <br>";

}else if (content_fields == 'hours') {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}else if (content_fields == 'URL') {

result += "<color name=black>" + "URL: " + Provider.GetFieldValue(row, content_fields)+ "<br>";

} else {

result += "<color name=black>" + Provider.GetFieldValue(row, content_fields)+ "<br>";

}

 

}

 

}

 

result += "<br></p>";

 

}

 

return result;

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...