Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Customize & Extend
Answered

How can I determine which control was used to add an attachment?

(0) ShareShare
ReportReport
Posted on by 113

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. 

anwarluck_2-1692253578545.png

 

Thanks in advance. 

  • Verified answer
    Anwarluck Profile Picture
    113 on at
    Re: How can I determine which control was used to add an attachment?

    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.");
    		}
    	});
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 69 Super User 2025 Season 1

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 49 Most Valuable Professional

#3
Jon Unzueta Profile Picture

Jon Unzueta 43

Featured topics