web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How can I determine wh...
Power Pages
Unanswered

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. 

Categories:
I have the same question (0)
  • Verified answer
    Anwarluck Profile Picture
    113 on at

    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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard