Jorge - Thursday, March 12, 2009 12:18 AM:
Hi Everyone,
I am new to Aras. I have been trying hard for 2 days now to figure out how to get this thing done.
I have a form where I have following fields, Unit Price, Currency (Dropped down list), Rate, New Price. What I am trying to accomplish is to trigger an event whenever I change the Currency whereby I will do the following:
(1) Get the Currency (value) from the dropped-down list
(2) Retrieve the Rate from the ItemType called 'Exchange_Rate' using the Currency.
(3) Compute for the New Price (Unit Price * Rate)
(4) Display Rate and New Price in the form.
I believe this can be accomplished in ARAS but I have no exact idea how to do it. An example will be vey much appreciated. We are planning to build a simple Inventory System in Aras but right now my 'ninja' skills can't get it right, I am stucked!!! Help anyone?
Thanks and best regards,
Jorge
tstickel - Thursday, March 12, 2009 11:45 AM:
Jorge;
Have you looked at the Innovator Programmer's Guide for help on client events, especially client form events? You will need to write a Java Script method to accomplish what you are trying to do. You will also have to modify your form definition to call this Java Script method as an onChange field event for the Currency field. Can I assume that you are familiar with Java Script coding?
Also, in your Step 4 you want to display the Rate and New Price on the form. Do you also want to save these values in the database? I assume that your form is linked to an ItemType that has properties: unit_price, currency, rate, new_price.
After getting the answers to these questions, I can help you more with the solution.
Jorge - Thursday, March 12, 2009 11:13 PM:
Hi Tstickel,
Thank you for your immediate response. I really appreciate it.
To your questions:
(1) I can honestly say that I have a limited experience in JavaScript codings but I can easily familiarize myself once I see few sample codings. It has been a long time that I studied JavaScripts and I havent actually done anything major using it.
(2) I have looked at Innovator Programmer's Guide especially client form events and made few testings and samples but I am failing miserably.
(3) Yes, I have another ItemType called 'Item_Master' where I have those properties and I will save these values in the database.
I have done few business applications myself already but on different RAD ... and that ofcourse is another story...
Tstickel, it will be very very helpful indeed if you could provide me sample Methods especially on Client side. I am familiar with the Form and Field Events. But totally lost in writing those codings on the Client Side. :( We really need to get this Inventory Application done in no time, for we still have upcoming Job Scheduling Project very very soon. Viva ARAS!!!
tstickel - Friday, March 13, 2009 5:12 PM:
Jorge:
Here it is. You must call this Method as an onChange event for both the Price and Currency fields
// Create an Innovator object
var myInnov = new Innovator();
// Access values for Price and Currency, one of which was changed and triggered this method
var inPrice = document.getElementById("tprice").value;
var inCurrency = document.getElementById("tcurrency").value;
// Get exchange rate from database
var exchItem = myInnov.newItem("texchange","get");
exchItem.setProperty("tcurrency",inCurrency);
exchItem = exchItem.apply;
// If Exchange rate was not found then its an error
if (exchItem.isError) {
alert("Currency " + inCurrency + " not found in Exchange table");
}
else {
// Now update fields on the Form and call handleItemChange to make same updates to the database when the Form is saved
document.getElementById("trate").value = exchItem.getProperty("trate"); // Rate may not have changed
handleItemChange("trate", document.getElementById("trate").value);
document.getElementById("tnew_price").value = exchItem.getProperty("trate") * inPrice;
handleItemChange("tnew_price", document.getElementById("tnew_price").value);
}
Jorge - Saturday, March 14, 2009 12:27 AM:
Hi Terry,
There is one word to describe what you posted.
"EXCELLENT!!!"
This gave me the whole idea in moving forward in developing more Business Applications in ARAS!
"WOW". Thank you so much!
Thanks and Best Regards,
Jorge
RonCK - Wednesday, March 25, 2009 3:29 PM:
Tstickel,
I'm trying to implement something like your code to have a value selected in a drop-down box on a form get copied to another field in the Item. I'm not sure if it's right, but I'm implementing the method as Javascript on the client side on the onChange event for the field.
I get a little lost looking at line 7. What is "texchange"? I figured that since the form is editing a class of part, that "Part" should be the correct answer there. This does not seem to be the case. I get an error that no entity of type "Part" exists. Any bright ideas?
best regards,
RonCK
tstickel - Wednesday, March 25, 2009 4:27 PM:
RonCK
Your case is easier than what Jorge was trying to do. Suppose you have an itemtype with the following
2 properties:
Name Label Data Type Data Source Length
tlist Units List List Units
tunits From List String 30
The List item data source, "Units", already exists in Innovator
Then have the following method called as an onChange event method for tlist:
document.thisItem.setProperty("tunits",this.value);
document.getElementById("tunits").value = this.value;
In this Javascript, "this.value" refers to the value that was selected from the pulldown list.
For methods called as onChange events on lists, the "this" ojects refers to an HTML Select Element.
So the first line of the method copies this value over to another property, tunits. When
the Form is saved this will also automatically update the database. The second line of the
method copies the selected value to the opened Form, so that the user immediately can see
the change. If this second line was not there then the user would have to re-access the
record so see the change.
RonCK - Wednesday, March 25, 2009 4:51 PM:
Thanks very much Terry! That did work. We were definitely over thinking it. We kept going after I posted last, and this is what I had last.
// name: SetCapValue
// purpose: copy the value from Capacitance Value to Component Value
// created: 09/03/23 by RonCK
// Create the Innovator Object
var myInnov = new Innovator();
// Get the Part Number of the Item being edited to fetch the record
var myPN = document.getElementsByName('item_number')[0].value;
// Query the Active Item from the Server
var qryItem = myInnov.getItemByKeyedName("Part",myPN);
// Get the Cap value from the Form
var CapValue = document.getElementsByName('capacitor_value')[0].value;
// Update the Component Value on the Form
document.getElementsByName('component_value')[0].value = CapValue;
// Update the Component Value on the Server
qryItem.setProperty("component_value",CapValue);
qryItem = qryItem.apply;
This updates the Component Value on the Form, but it does not save it to the server when you exit the form. Any idea, why that was wrong?
thanks again and best regards,
RonCK
tstickel - Friday, March 27, 2009 3:21 PM:
RonCk
In your method, qryItem was created using getItemByKeyedName. The AML that is generated will have the item's action attribute set to "get" not "edit". In fact, the statement, "var qryItem = myInnov.getItemByKeyedName("Part",myPN);", actually does nothing more than set up the AML, it does not execute the query. The execution of the query does not happen until you apply the query, which you did in your last statement, "qryItem = qryItem.apply;".
So the database was not updated because all you told innovator to do was to retrieve the Part that has its keyed name = myPN.
To update the database you need to this
var qryItem = myInnov.getItemByKeyedName("Part",myPN);
qryItem = qryItem.apply; // This will run the query and either return an Item or an Error (if the part you are looking for does not exist)
if (qryitem.isError) {alert("Part not found " + myPN)}
else {
qryItem.setAction("edit"); // change the action in qryItem from "get" to "edit"
qryItem.setProperty("component_value",CapValue);
qryItem.apply; // This will now update the database because it is applying an "edit" action
}
Disclaimer: I did not run this code, so it may have a coding error in it.
Hope this helps