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
Page 1 / 1
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 = splitFileNameesplitFileName.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.
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
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:
$("divvID$='_FilePanel']").
.SFCLabel('option', 'text', Extension);
Where does this come from.
Thanks
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.
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.
Hi all,
I have reused solution by @Asad_Naeem (thank you for posting it) to get both file extension and name with replace extension in workflow. With extracted extension, it was easy to get name and add different extension.
But I have recently faced issue with document name ending with two dots like “documentName..doc”, so I updated original solution with Replace function which first replaces any occurance of two consecutive dots (docName,..,.), rest of logic could remain same.
Hope that this helps somebody (including myself) to save some time.