Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Determine Attachment format in Archer

RupadarshiniKan
Contributor III

Hi All,

 

I'm trying to find format of attachemnt to restrict to one file type. Howver unable to do so. I see that when I include attachments in report and export, I can get metadata hence tried writing custom object. It is failing to read content in attachment i.e. file name. It reads as

 

Attachment name is 8787.

 

Below is part of the snippet. Any advise/suggestion is appreciated!

 

function mySaveClick() {

var attachment_fieldID=35838;

var fileExtension;

var invalidCounter=1;

var fileName;

 

fileName=String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(attachment_fieldID,false));

fileExtension=/[^.]+$/.exec(fileName);

alert("Attachment name is "+fileName+"extension is"+fileExtension);

if ( (fileExtension=="xls")||(fileExtension=="xlsx") ){

invalidCounter=0;

}

if (invalidCounter!=0){

alert(fileExtension+"is invalid format");

}

}

</script>

6 REPLIES 6

Anonymous
Not applicable

If it's instance wide you can do this via the "File Creation Restriction" tab on the Archer Control Panel - use the 'WhiteList'.

 

If it's for a specific attachment field, then i am no help to you. It would be an interesting enhancement request though?

Thanks Martin,

 

It is only per field in an application, not instance wide..

DavidPetty
Archer Employee
Archer Employee

So you only want the user to upload only Excel files for this particular attachment field?

 Advisory Consultant

Yes David

FELIXKJOY
Contributor III

Hi Rupa,

 

you should submit an idea for this enhancement.

GeoffTaylor2
Contributor III

Hi Rupa,

 

This isn't the most elegant solution (and it almost certainly isn't future-proof), but you can get the file name from the DOM by finding the <a> elements that have an href that ends with 'Type=Attachment'. The file name is in the <a> element's title attribute.


This works for me in 6.4 SP1 (it works even if the file name contains dots):

 

<script type="text/javascript">
var regex = /^.+\.(.+)$/;
var allowedExtensions = ["xlsx", "xls"];
var fId = 21334; // ID of Attachments field

function checkFileExtensions() {
attachments = $("#" + ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(fId).clientId).find("a[href$='Type=Attachment']");

for (att of attachments) {
filename = att.getAttribute("title");
fileMatch = filename.match(regex);

if (fileMatch != null && fileMatch.length > 1) {
extension = fileMatch[1];

if (!allowedExtensions.includes(extension)) {
alert(extension + " is an invalid format!");
}
}
}
}
</script>

 

Just call checkFileExtensions() when you want to validate the attachment types.