[email protected] - Monday, August 29, 2011 3:30 PM:
Hi, All:
I'm trying to trigger a server method from a button click. I kept getting errors so I whittled down my code until there were only two lines left, and it still throws an error:
Innovator inn = this.getInnovator();
return inn.newError("Locations:");
The error message says "Object expected Client side error". I've attached the method to a button named btnSubmit, and set the fieldEvent to "onClick". I have no idea why it won't work; completely stumped. Any suggestions?
Jeremy B.
Brian - Tuesday, August 30, 2011 6:30 AM:
Hi Jeremy,
The "this" context of a button press is the button not the document. And you are writing c# code in what shoud be a Javascript (client) method.
You should have code like:
var ctx = this.document.thisItem;
var inn = ctx.getInnovator();
Then you should be calling a "generic method" on the server side.
See the programmers guide for "context" and "generic method"
Cheers,
Brian.
[email protected] - Tuesday, August 30, 2011 10:33 AM:
Thanks, Brian!
Wow, there is a really key concept here that wasn't covered in ARAS programming class. I'm a .net programmer and I normally trigger server methods from buttons and set form values from server side. I assumed that since ARAS was built on the dot-net framework I would be able to use the same approach, but I guess not.
I have changed my method to Javascript and can successfully call a separate server method using applyMethod(). Now I have a new problem... I can't locate the label on the form. Normally I would use var field1 = document.all.LabelName; or var field1 = getFieldByName("LabelName"); but neither one is working. Can you help me understand what is happening? Here's what I've got so far:
var ctx = this.document.thisItem; //Is this getting the form as the context item?
var inn = ctx.getInnovator();
var result = inn.applyMethod("AP_CDC_webservice", "");
var field1 = ctx.getFieldByName("lblResult"); //the label I want to work with is named "lblResult"
field1.innerHTML = result;
I've used an Alert popup to verify that the webservice is returning a value, and it is. I get an error that indicates I am not finding the label, however, so when I try to set its value the method fails. I suspect this has to do with context again, but I thought the "ctx" value here was the correct context item (i.e. the document). Is that not correct?
Thanks again,
Jeremy B.
Brian - Wednesday, August 31, 2011 1:49 AM:
Hi Jeremy,
I realised a small mistake in the code snippet I gave you.
var ctx = document.thisItem;
This gets you the Item underlying the form. So if you called this on the "Part" form you would be getting the "Part" Item with the data that was already added to the form by the user.
To get input type fields (text, combo box etc) you need to use the "document'.
var txt1 = document.getElementsByName("textFieldName");
txt1[0].value = "some value";
The labels do not behave in quite the same way.
Aras has a getFieldByName implementation that should work here.
var lbl = getFieldByName("lblResult");
lbl.innerHTML = "the value you want to display";
I tried this on a form in the "onLoad" method and it works for me.
Hope this helps,
Brian.
[email protected] - Wednesday, August 31, 2011 9:05 AM:
Thanks again, Brian.
If it is helpful to anyone else reading this thread trying to solve a similar problem, here is a simple version of the final, working code:
//Javascript method that fires on button click. Calls server side method that calls a web service and returns a short string value. Display
//the string on a label on the form:
var ctx = this.document.thisItem;
var inn ctx.getInnovator();
var result = inn.applyMethod("AP_CDC_webservice", "");
var field1 = getFieldByName("lblResult"); //Locate the label
field1.innerHTML = result; //Display the results
-Jeremy B.
bellis - Wednesday, August 31, 2011 3:20 PM:
Hi Jeremy -
Sorry you found this confusing. Client events always use the JavaScript language and have access to the IOM - I guess this was not made clear to you in class. Chapter 9 - Creating Client Event Methods discusses the options for working with the client in the Developing Solutions class and the correct way to address the context Item. If you have any other issues let us know!
Best,
Bob Ellis
[email protected] - Wednesday, August 31, 2011 4:55 PM:
Hi, Bob!
Yeah, I routinely trigger server methods from button clicks when I work in .net, and set text values from server side. I just had it stuck in my head that since ARAS was built on top of .net I would be able to do exactly the same things, and I was really confused about why it wasn't working. No worries, I'm back on track now. :)
Thanks,
Jeremy Byrne