John Example - Tuesday, September 22, 2015 5:01 AM:
Hi,
according to my task I need to import lots of Items from external file. So, I wrote a server-method for import procedure but it uses fixed filepath which was set in the code as a string value. What I'd like to do is to allow a user choose a full filename via custom Form or Dialog Window.
My question is how can I do this? I tried to look at default Forms such as CAD Form, which as I thought has to get a filepath somehow, but I can't get how the Field "File Item" works. Do I need to use some specific Field Type or maybe I can just call a dialog window someway?
Thank you in advance.
zahar - Tuesday, September 22, 2015 8:33 AM:
The question is what you want to happen when the user select the file?
It needs to be sent to you? (aka uploaded to aras vault and the you can access to this file from the server)
- or -
You just want to know the path of the file?
Do you want this operation Sync or ASync?
John Example - Tuesday, September 22, 2015 8:46 AM:
What I want to do is to get the file path which was chosen by user and then pass it to a server method right after I get it. I guess it has to be uploaded to aras vault.
zahar - Tuesday, September 22, 2015 9:28 AM:
Create an action with a method in JS:
- If you don't need to upload the file, then this is your JS code:
var vaultApplet = top.aras.vault;
var clientPath = vaultApplet.SelectFile();
if(clientPath === null || clientPath === ""){return;}
var methodAML = "<file_path>" + clientPath + "</file_path>";
var result = top.aras.applyMethod("YOUR_SERVER_METHOD", methodAML);
- If you do need to upload the file then this is your JS code:
var vaultApplet = top.aras.vault;
var clientPath = vaultApplet.SelectFile();
if(clientPath === null || clientPath === ""){return;}
var fileItem = this.getInnovator().newItem("File","add");
fileItem.setFileName(clientPath);
var resultedItem = fileItem.apply();
var fileId = resultedItem.getID();
var affectedId = this.getRelatedItem().getID();
var methodAML = "<file_id>" + fileId + "</file_id>";
var result = top.aras.applyMethod("YOUR_SERVER_METHOD", methodAML);
John Example - Tuesday, September 22, 2015 11:02 AM:
Works perfectly! Thank you for your help.