I have a basic form, and have added multiple attachment controls (3) that allows me to add files, which is working fine, it creates attachment in notes.
The problem is I am unable to identify from which control was the file added, which is required to identify.
Example:
I have 3 control for attaching profile photo, id card, Utility bill files respectively. Once user submits the form, Dynamics adds it as attachment to the related record let say Contact. But the problem here is, I am unable to identify whether which file was added from which control.
Thanks in advance.
This has been resolved.
I have simply used a javascript that on selection of file by the user triggers a function that renames the file according to business requirement.
Adding the code, if someone else needs it.
//on load of form, call this function with attachment id
function attachEventHandlerToFile(id) {
// Get a reference to the file input element
var fileInput = document.getElementById(id);
// Add event listener to the file input element
fileInput.addEventListener("change", function (event) {
// Get the selected file (if any)
var selectedFile = event.target.files[0];
if (selectedFile) {
var investorCompany = $("#ipaq_investorcompanyname").val();
var fileName = "modifiedname";
// Store the modified filename
var modifiedFilename = fileName + selectedFile.name.slice(selectedFile.name.lastIndexOf("."));
// Create a copy of the selected file
var modifiedFile = new File([selectedFile], modifiedFilename, { type: selectedFile.type });
// Clear the file input
fileInput.value = "";
// Create a new FileList with the modified File object
var modifiedFileList = new DataTransfer();
modifiedFileList.items.add(modifiedFile);
// Set the value of the file input to the modified FileList
fileInput.files = modifiedFileList.files;
console.log("File selected: " + modifiedFilename);
} else {
console.log("No file selected.");
}
});
}
Fubar
69
Super User 2025 Season 1
oliver.rodrigues
49
Most Valuable Professional
Jon Unzueta
43