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 - Access to a form's content from a Server method

acejazz - Wednesday, May 8, 2013 9:55 AM:

Hi to everybody,
I am a newbie in Aras and I have a problem.

I created a custom form in which there is a dynamic HTML table filled by data from the Server extracted from different tables.

http://min.us/lHjsl3XqfnB1Z


Obviously, if I click Save button in toolbar, Aras can't store information that is in custom HTML code and in dynamic form.

I would to use that Save button to store even information in custom form. How can I do?

http://min.us/lf51wEiYeGCsV


At the moment, I created another button "Save table" that reads information from the whole form (by methods document.getElementById("...")) and switch it in right tables.
I would to add a Server Method onAdd()  that should execute right operations, but I don't know how I can access to that custom form from the Server method, because when I use keyword "this" I can access only to that Item istance.
With that method I should read the form and use information in it to modify database entities.

Thanks in advance.



Brian - Friday, May 10, 2013 6:46 AM:

Hi acejazz,

Have a look at Generic methods in the programmers guide. From your form click your save table button and put some xml together with the details you want to pass to the server method. Then call the server mdthod and pass the xml as the "body" of the method.

In the server method you will have access to body xml that you passed in via this.getProperty (...).

Hope this helps.

Brian



acejazz - Friday, May 10, 2013 12:39 PM:

Hi Brian, thanks for attention.

I already used that kind of method and it works well, but I want to replace my "Save table" button with "Save" button in default toolbar.

http://min.us/lD417i3jqw8kV


The fact is that if I use, default save button, I can't control the way Aras read the form. I got that I can change server Methods like beforeAdd(), onAdd() and afterAdd(), but how can I pass relevant information from the form to one of those functions?
In my form there are 2 buttons: one for save table ("save table") and the other one for save the Item properties. Well, I would to custom "Save button" behavior in toolbar to read my form and to work as I want.

I hope to be clear now and sorry for my english..



Brian - Friday, May 10, 2013 4:16 PM:

Hi Acejazz,

Add a property to the item type so that you can temporarily pass the information from the form to the server method. - Say property name = table_contents

On the form. Add a method to the html field triggered "onChange" to update the new property.

Use "handleItemChange( propertyName, newValue)" 

to put the information from the html table into the field.

In the server method triggered in onBeforeAdd and onBeforeUpdate you will now have access to the contents of the table via the temporary field.

string tableContents = this.getProperty("table_contents","");

Then you can clear the the temporary field before you actually save the data.

this.setProperty("table_contents","");

// your code to update the database per the save table button actions

return this;  // to allow the save method to continue.

Hope this helps,

Brian.



acejazz - Friday, May 10, 2013 4:18 PM:

This is a good idea!
I will try it and I will let u know!

Thanks a lot, Brian!