ASAP:Need Help on Code

Could anyone indicate to my why the following code displays the attachments
with the same/similar filenames twofold (double) in the browser?

Any help will be much appreciated.

Nayiri

The Code:

attNames:= @LowerCase(@AttachmentNames);
allowed:= “doc”:“pdf”:“ppt”:“xls”:“rar”:“zip”;

tmpList:= @Trim(@LeftBack(@ReplaceSubstring(attNames; “.” + allowed;
“Dummy”); “Dummy”))
*+ (“.” + allowed);

RemoveList:= @Trim(@Replace(tmpList; attNames; “”));

@Trim(@Replace(tmpList; RemoveList; “”));

@Implode(“{<a href="” + @Text(@DocumentUniqueID) + “/$file/” +
@Trim(@Replace(tmpList; RemoveList; “”)) + “" target="_blank"
class="links">” + “” + @If(@Contains(@Right(@Trim(@Replace(tmpList;
RemoveList; “”)); 3); “doc”: “pdf”: “xls”: “ppt”: “rar”: “zip”);
@Replace(@Right(@Trim(@Replace(tmpList; RemoveList; “”)); 3); “doc”: “pdf”:
“xls”: “ppt”: “rar”: “zip”;
“<img border=0 hspace="4" width="18" height="18" src=…/word.gif
Alt="Click here to open the Word file" title="Click here to open the Word
file">”:
“<img border=0 hspace="4" width="18" height="18" src=…/pdf.gif
Alt="Click here to open the PDF file" title="Click here to open the PDF
file">”:
“<img border=0 hspace="4" width="18" height="18" src=…/excel.gif
Alt="Click here to open the Excel worksheet" title="Click here to open the
Excel worksheet">”:
“<img border=0 hspace="4" width="18" height="18" src=…/ppt.gif
Alt="Click here to open the Power Point presentation" title="Click here to
open the Power Point presentation">”:
“<img border=0 hspace="4" width="18" height="18" src=…/rar.gif
Alt="Click here to download the Rar file" title="Click here to download the
Rar file">”:
“<img border=0 hspace="4" width="18" height="18" src=…/winzip.gif
Alt="Click here to download the Zip file" title="Click here to download the
Zip file">”); “”) + @Trim(@Replace(tmpList; RemoveList; “”));“
]”)

Subject: ASAP:Need Help on Code

When dealing with multi-value lists, actions occur across all members of the list.

For example, in this bit of code, the (“.” + allowed) portion will iterate across all values of allowed

and NOT just the matched value of allowed.

attNames:= @LowerCase(@AttachmentNames);

allowed:= “doc”:“pdf”:“ppt”:“xls”:“rar”:“zip”;

tmpList:= @Trim(@LeftBack(@ReplaceSubstring(attNames; “.” + allowed; “Dummy”); “Dummy”))

*+ (“.” + allowed);

You have to iterate across the elements to determine which extension actually matched.

I’ve taken a few minutes of free time to rejig your code. See below.

Adjust to taste.


attNames:= @LowerCase(@AttachmentNames);

allowedExt:= “.doc”:“.pdf”:“.ppt”:“.xls”:“.rar”:“.zip”;

aref := “”;

aref1 := “<a href="” + @Text(@DocumentUniqueID) + “/$file/”;

aref2 := “" target="_blank" class="links"><img border=0 hspace="4" width="18" height="18" src=…/”;

aref3 :=

“word.gif Alt="Click here to open the Word file" title="Click here to open the Word file">”:

“pdf.gif Alt="Click here to open the PDF file" title="Click here to open the PDF file">”:

“ppt.gif Alt="Click here to open the Power Point presentation" title="Click here to open the Power Point presentation">”:

“excel.gif Alt="Click here to open the Excel worksheet" title="Click here to open the Excel worksheet">”:

“rar.gif Alt="Click here to download the Rar file" title="Click here to download the Rar file">”:

“winzip.gif Alt="Click here to download the Zip file" title="Click here to download the Zip file">”;

@For(m := 1; m <= @Elements(allowedExt); m := m + 1;

ext := allowedExt[m];

@For(n := 1; n <= @Elements(attNames); n := n + 1;

newAref := @If(@Contains(attNames[n]; ext); aref1 + attNames[n] + aref2 + @Replace(ext; allowedExt; aref3); “”);

@If(newAref != “”; aref := aref : newAref; “”)

)

);

aref := @Trim(aref);

@For(m := 1; m <= @Elements(aref); m := m + 1;

@Prompt([Ok]; “Generated Arefs”;aref[m])

);

@All

Subject: RE: ASAP:Need Help on Code

Andrew thank you very much for your valuable assistance.

Subject: RE: ASAP:Need Help on Code

Im sorry to disturb you again Andrew but I am encountering a problem with the very useful suggested code. I have managed to display my attachments in the browser in the form of an image however I am unable to display their filenames.

Any suggestions will be MUCH appreciated.

Thanking you in advance,

Nayiri Y.

Subject: RE: ASAP:Need Help on Code

The filenames are stored in the attNames variable, you just have to extend the code to show these.

I also notice that you didn’t close the tag.

Here is a version that appends the file name within the anchor tag in order to make the name linkable too.

We change the line:

newAref := @If(@Contains(attNames[n]; ext); aref1 + attNames[n] + aref2 + @Replace(ext; allowedExt; aref3); “”);

to

newAref := @If(@Contains(attNames[n]; ext); aref1 + attNames[n] + aref2 + @Replace(ext; allowedExt; aref3) + " - " + attNames[n] + “”; “”);

Subject: RE: ASAP:Need Help on Code

Once again thank you very much Andrew for your valuable help.