#1
|
|||
|
|||
![]()
I'm working on a project where images are returned from an external data file. The user can make up to three choices from drop-downs. In the ExDF, several drop-down options may point to the same image file. The client does not want duplicate images, so I put together the code below. If options are chosen for all three fields, it works great.
Code:
var externalDF = new ExternalDataFileEx("Competitor-ExDF.xlsx", "Excel"); var a = externalDF.FindRecord("CompetitorDropDown", Field("CP-Product-1-A")); var b = externalDF.FindRecord("CompetitorDropDown", Field("CP-Product-1-B")); var c = externalDF.FindRecord("CompetitorDropDown", Field("CP-Product-1-C")); var caseA = ((externalDF.GetFieldValue(a, "CompetitorImage"))); var caseB = ((externalDF.GetFieldValue(b, "CompetitorImage"))); var caseC = ((externalDF.GetFieldValue(c, "CompetitorImage"))); var resultA = Resource(externalDF.GetFieldValue(a, "CompetitorImage")).content; var resultB = Resource(externalDF.GetFieldValue(b, "CompetitorImage")).content; var resultC = Resource(externalDF.GetFieldValue(c, "CompetitorImage")).content; if ((caseA != caseB) && (caseA != caseC) && (caseB != caseC)) {return resultA + " " + resultB + " " + resultC;} if ((caseA == caseB) && (caseA != caseC)) {return resultA + " " + resultC;} if ((caseA == caseB) && (caseA == caseC)) {return resultA;} if ((caseA != caseB) && (caseA == caseC)) {return resultA + " " + resultB;} if ((caseA != caseB) && (caseA != caseC) && (caseB == caseC)) {return resultA + " " + resultB;} else return ""; Thank you for looking! Last edited by LisaHansen; April 21st, 2022 at 03:49 PM.. Reason: Added information |
#2
|
||||
|
||||
![]()
Would this work?
Code:
var externalDF = new ExternalDataFileEx("Competitor-ExDF.xlsx", "Excel"); var unique = function (value, index, self) { return value ? self.indexOf(value) === index : false; }; var getResource = function (value) { var fieldValue = externalDF.GetFieldValue(value, "CompetitorImage"); return fieldValue ? Resource(fieldValue).content : ''; }; return ["CP-Product-1-A", "CP-Product-1-B", "CP-Product-1-C"] .map(Field) .filter(unique) .map(getResource) .filter(String) .join(' ');
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
#3
|
|||
|
|||
![]()
Thank you so much for checking this out, Step!
Currently, my tag file has data in all three fields. With your code, I get this error: uncaught exception: Error: In Resource(), no resource named CompetitorImage. I put my code back and it works again (with all three fields having data). I did test yours with B & C having no data and received the same result as with all three populated. |
#4
|
||||
|
||||
![]()
Whoops I forgot to get the record from the external data field. Try this:
Code:
var externalDF = new ExternalDataFileEx("Competitor-ExDF.xlsx", "Excel"); var unique = function (value, index, self) { return value ? self.indexOf(value) === index : false; }; var getResource = function (value) { var competitor = externalDF.FindRecord("CompetitorDropDown", value); if (competitor) { var competitorImage = externalDF.GetFieldValue(competitor, "CompetitorImage"); if (competitorImage) { return Resource(competitorImage).content; } } return ''; }; return ["CP-Product-1-A", "CP-Product-1-B", "CP-Product-1-C"] .map(Field) .filter(unique) .map(getResource) .filter(String) .join(' ');
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
#5
|
|||
|
|||
![]()
This one works if any or all of them exists, however, it's allowing the duplicate image. Unfortunately, that's the reason I fell down this rabbit hole. In my tag, I have three different choices for A, B & C, they all point to the same image in the ExDF. It's showing that image three times instead of just showing it once.
Could you explain the logic in lines 2 & 3 for me, please? I've not seen that before and would love to understand what you had in mind there. I did try changing false to true in line 3, no dice. I appreciate you! |
#6
|
|||
|
|||
![]()
Hold up! Slight tweak and you did it!!!
I flipped your filters at the bottom so .filter(String) was first and .filter(unique) was second. I figured it needed the resource before it could know if it was unique or not. You are brilliant! Thank you! |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|