This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Creating dialog with user for custom file action

Leon Schmetz - Wednesday, March 7, 2012 7:44 AM:

Hello,

I am new to the forum. I am also relatively new to ARAS. I have been given the nice task to introduce ARAS into our organization. I have written a custom import for our PDM information and we have successfully import Parts,BOMs, Manufacturer Parts and Documents.

I would now like to add a custom action for files. So I have created an Action, added the Action to the Item Type and created 2 javaScript methods. Method1 executes when the Action is triggered and contains code like

var qryItem = this.newItem("Document File", "get");
qryItem.setID(this.getID());
var result = qryItem.apply();

if (result.isError()) alert('Error : Document file not found');

var fileId = result.dom.selectSingleNode("//Item/related_id/Item/id");
var fileId = result.dom.selectSingleNode("//Item/related_id/Item/id");

 

Next I use showModalDialog to popup a custom form like this

var formNd = top.aras.getItemByName("Form", "Do with file", 0);
if (formNd)
{
  var param = new Object();
  param.title = "Do with file";
  param.formId = formNd.getAttribute("id");
  param.aras = top.aras;
  param.docfile = this.getID();
  param.file = fileId.Text;
  var width = top.aras.getItemProperty(formNd, "width");
  var height = top.aras.getItemProperty(formNd, "height");
  showModalDialog("ShowFormAsADialog.html", param,
          "dialogHeight:" + height + "px; dialogWidth:" + width + "px; " +
          "status:0; help:0; resizable:0; scroll:0;");
}

Then in the onLoad event for the form I call Method 2, also in javaScript. And then the fun starts.
I have put "debugger" statements in both scripts and was able to verify that the ARAS-methods available in Method1 and in Method2 are different.
For example writing
var aras   = dialogArguments.aras;
var qryItem = aras.newItem("Document File", "get");
qryItem.setID(dialogArguments.docFile);
qryItem.apply();
will not work! because method setID() and apply() are both not available in the new context.
So what am I missing? What should I do to make it work?
Any help is appreciated!
Leon

 

 

 



Leon Schmetz - Monday, March 12, 2012 9:59 AM:

Hello everybody,

 

I had hoped someone would respond to my question. It has taken me a week to complete the function I had in mind.

I have replaced the lines in question with these

var aras   = dialogArguments.aras;

var qryItem = aras.IomInnovator.newItem("Document File", "get");

qryItem.setAttribute("action", "get");

qryItem.setAttribute("id", dialogArguments.docfile);

var result = aras.applyAML("<AML>"+qryItem.dom.xml+"</AML>");

These work!
Because users sometimes check in files with the wrong name, I have now a working function that is authorized for administrators to rename files.
Regards,
Leon



Leon Schmetz - Thursday, March 15, 2012 9:02 AM:

Just to let you know, the only thing that was breaking my initial code was

 

var aras = dialogArguments.aras;

 

When I replace this line with

 

var aras = new Innovator();

 

everything works as expected.

The only point of attention is that I still have to pass the aras object via the dialogArguments.

So I hope all this helps developers starting out with Aras.

 

Leon