cancel
Showing results for 
Search instead for 
Did you mean: 

WD Attachments

Former Member
0 Kudos

I am developing a Purchase Requisition application in Web Dynpro and one of the things I have to figure out is how to allow a user to attach documents with things like quotes from multiple suppliers, a justification form if the purchase is over a certain dollar value, etc.

I know that I can use the UI Download/Upload elements to upload a file to the server and I imagine I could do something with storing these documents in a certain KM folder.

Today as I was logged on to service.sap.com I had to attach a file to a customer message and realized that the solution there would be perfect for my problem as it would allow a user to attach any files and allow someone who's going in to the purchase req to approve it to view the documents that are stored on the server. Does anyone know if this is being done via the FileUpload/FileDownload UI elements? The tutorials don't do a good job of explaining how to work with files once they are uploaded to the context - was hoping there was something that helped to take it to the next level and allow the WD to manage the documents. Any hints would be appreciated.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Dana

Bind a FileUpload UI element's "Data" property to a context attribute of type binary.

Add a button to the view. In the on action method of the button add the following code to upload the file in KM.


	try {
		IWDClientUser clientUser = WDClientUser.getCurrentUser();
		com.sap.security.api.IUser sapUser = ClientUser.getSAPUser();
		IUser epUser = WPUMFactory.getUserFactory().getEP5User(sapUser);
		IResourceContext resourceContext = new ResourceContext(epUser);
		IResourceFactory resourceFactory = ResourceFactory.getInstance();
		RID ridPath = RID.getRID("Absolute_Folder_Path_In_KM_Where_To_Upload_The_File"); // ex /documents/purchase_requisition
		IResource resource = resourceFactory.getResource(ridPath,resourceContext);
		ICollection collection = (ICollection)resource;
		ByteArrayInputStream iStream = new ByteArrayInputStream(wdContext.currentContextElement().getFileToUpload()); // context attribute FileToUpload is binary type,directly under root context node, FileUpload ui element's data property is bound to this attribute
		IWDModifiableBinaryType type = (IWDModifiableBinaryType)wdContext.getNodeInfo().getAttribute("FileToUpload")
			.getModifiableSimpleType();
		Content content = new Content(iStream,type.getMimeType().getHtmlMime(),-1);
		collection.createResource(type.getFileName(),null,content); 
	}
	catch(Exception exception) {
		// necessary actions
	}  

Also add the following piece of code to wdDoInit() method of the view.


		IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute("FileToUpload");
		IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();

You need to add the necessary jar files to build path to use KM api and a sharing reference "PORTAL:sap.com/com.sap.km.application" to Web Dynpro references of your project. See this link.

<a href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/using%20knowledge%20management%20functionality%20in%20web%20dynpro%20applications.pdf">Using KM functions in Web Dynpro</a>

Hope this is of any help.

Regards

kk