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 - Accessing Field Data on the Current Form with Client Method

markW - Tuesday, May 15, 2007 4:58 PM:

My overall goal is to have a button on an open form.

Click the button to trigger a method, which creates a new Item, names the Item based on the Item name where the button is clicked, then opens up the form for the new Item.

I think I am 2/3rds of the way home.

I have built and tested the following method and it works fine.  Basically, if I provide the name for the new item the Item will be created on the button click, and then the new form will open.  It is probably a bit bloated and forceful, but I only need working at the moment, not pretty.

var innovator = new Innovator();

var createdistr = innovator.newItem("Idea_Asses_Distribution_P2", "add");
createdistr.setProperty("idea_assess_distribution_p2_name","idea_dist1");
result = createdistr.apply();

var innovator2 = new Innovator();
var qryitem = innovator2.newItem("Idea_Asses_Distribution_P2", "get");
qryitem.setProperty("idea_assess_distribution_p2_name","idea_dist1","eq");
var result2 = qryitem.apply();
if (result2.isError()) {top.aras.AlertError(result2.getErrorDetail());}
top.aras.uiShowItemEx(result2.node,"tab view",true);

Now, I want to read the property:  "idea_name" from the Item which is the open form with the button which calls the method.

So, I did a little test from the console to make sure the name field I wanted could be accessed if I just retrieved the Item with a get:

var field = new Item("Idea_P2","get")
field.setProperty("idea_id","999aaa","eq");
var result = field.apply();
var name = result.getProperty("idea_name");

writeResults(name);

That worked fine, the name value returned in the console.  So now, doing it from the form.  I am not sure how to call the Item which is shown in the form and get the property.  From the documentation I thought I just simply used document.thisItem.  So, I tried the following:

var name = document.thisItem.getProperty("idea_name");

var innovator = new Innovator();

var createdistr = innovator.newItem("Idea_Asses_Distribution_P2", "add");
createdistr.setProperty("idea_assess_distribution_p2_name",name);
result = createdistr.apply();

var innovator2 = new Innovator();
var qryitem = innovator2.newItem("Idea_Asses_Distribution_P2", "get");
qryitem.setProperty("idea_assess_distribution_p2_name",name,"eq");
var result2 = qryitem.apply();
if (result2.isError()) {top.aras.AlertError(result2.getErrorDetail());}
top.aras.uiShowItemEx(result2.node,"tab view",true);

 Basically the same code as works, but with the hardcoded item name replaced with the name variable which I hoped would be pulled from my first added line.  But, I get an error message saying that you can't save the new Item without the required name field (name property is required by the new Item I am creating).  So, clearly I am not properly getting the name field into my variable (or probably any entry into my variable, most likely null).

So, I assume it is a bit trickier then my simplistic effort (probably just a bit), but I can't figure it out from the examples in the documentation.

Any help would be appreciated.

Thanks in advance.

 Mark



markW - Tuesday, May 15, 2007 5:31 PM:

UPDATE:

 I changed my code to this:


var item = document.thisItem;
var name = item.getProperty("idea_name");


var innovator = new Innovator();

var createdistr = innovator.newItem("Idea_Asses_Distribution_P2", "add");
createdistr.setProperty("idea_assess_distribution_p2_name",name);
result = createdistr.apply();

var innovator2 = new Innovator();
var qryitem = innovator2.newItem("Idea_Asses_Distribution_P2", "get");
qryitem.setProperty("idea_assess_distribution_p2_name",name,"eq");
var result2 = qryitem.apply();
if (result2.isError()) {top.aras.AlertError(result2.getErrorDetail());}
top.aras.uiShowItemEx(result2.node,"tab view",true);

 Now it works!!!

 So, now if someone could explain to my simple little not very experienced programmer brain why this works and not the other, I would appreciate it.  Then I might even be able to reproduce my results on a similar effort.

:)



SamsAn - Wednesday, May 16, 2007 2:43 AM:

It seems that the difference between the methods does not play any role. Are different environments used for these two different methods (for example, idea_name property value may be NOT specified for the first case)? Anyway, in both methods alert(name); code line may be used to test the retrieved value.