Question

Find File Attachment extension


Hi

 

Can someone help me with javascript how to find/get file attachment extension below

PCR2001 Covance Lab Manual v1.0.pdf

 

I just want to get the 'pdf' back.

 

This is my script

Right ( File Name, Length ( File Name ) - Find ( File Name, . ) )

Hower when I did that I got back 0.pdf

 

thanks

 


10 replies

Can someone help? Thanks

Hi TTN,

 

Not sure using Inline functions, but  you can try below jQuery 

 

   < script > /* here selector id "#000000*personal details removed*0000_fe7066df-a84d-5108-bebc-33a11f22c222" is id of control having file name*/
     var fileName = $("#000000*personal details removed*0000_fe7066df-a84d-5108-bebc-33a11f22c222").val();
     
     var splitFileName = fileName.split(".");
     
     var fileExtention = splitFileName[splitFileName.length-1];
     /* here selector id "#000000*personal details removed*0000_fe7066df-a84d-5108-bebc-45c88f26e124" is id of control where you want to extention value        of file*/
     $("#000000*personal details removed*0000_fe7066df-a84d-5108-bebc-45c88f26e124").val(fileExtention);< /script >

 

change the selector id  in above query as per your controls ID, which you can get using developer option by pressing F12 key or (Ctrl+Shft+C)

 

 

let me know if this helps you.

Userlevel 6
Badge +10

Hi,


 


If you're trying to achieve this in SmartForms then there is no need to use JS, you can use the following expression:


 



 


Let me know if a script is required in your case.


 


 

I have to display the file extension when the user try to upload the attachment. And the file name will be different all the time

Userlevel 6
Badge +10

Hi


 


 UPDATE:


 


I see what you mean now, because you have 2 dots in the name. 


 


Unfortunately the only way is to use Java Script.


 


Apologies for the confusion

Do you have any good javascript I can start with.

How do you pass the dymanic file name to this string

 

var fileName = $("#000000*personal details removed*0000_fe7066df-a84d-5108-bebc-33a11f22c222").val();

 

Thanks.

Thanks, It work.

 

Questions:

How do you come up with these:

$("div[ID$='_FilePanel']").

.SFCLabel('option', 'text', Extension);

 

Where does this come from.

 

Thanks

Userlevel 6
Badge +10

Hi TTN,


 


$("div[ID$='_FilePanel']")

I am using the ID that ends with _FilePanel because the ID itself is dynamic and could change, so when you use the dev tool of the browser or inspect element, you should see the following:


 



 


I beleive that the _FilePanel is used for the attachment control and it is static so I used it as a selector.


 


.SFCLabel('option', 'text', Extension);

You can easily populate the data label control using  .val()..etc but Rules and actions in smartforms will not see the value because you gave the value to the html tag but not the text property 


 


This is the way to transfer data to a data label to make it usuable in smartforms.


 


Hope that explains it.


 


 

Understood. Again Thanks for your help.

Hi,

 

I have tried to do using out of the box functionality. I have made an expression which is like that. I am sure that it will work for all the files.

the requirement for me to use these files:

.pdf, .docx, .doc, .txt, .png, .jpeg, .jpg etc. It can be noticed that all these files extensions are 3 or 4 of length, not more than that so I fixed the length of 5 to read the last part of the file name.

The expression is:

Mid ( Right ( File Name, 5 ) , Find ( Right ( File Name, 5 ) , . ) , Length ( Right ( File Name, 5 ) ) )

 

for example

Details are:

Right ( File Name, 5 ) will read the 5 characters from right side of filename

Find ( Right ( File Name, 5 ), . ) will give the index of dot (.)

Length ( Right ( File Name, 5 ) ) will give the length of the string

 

Kindly suggest me any improvement if required.

 

Reply