Updating from data using c#

Hi, I need help. I'm doing something that should be easy, but no!!!.

I want to schedule an event that when the data is saved, save option, make me a count and update the form. I have created the onAfterUpdate event on the ItemType i tried  too onBeforeUpdate and the same.

I have a display (ItemType), with a related table. In this table they choose the vacation days of the year and when saving, I put an event so that it makes the sum of the chosen days and updates the corresponding ItemType attribute.

I have tried it by AML code, but it gives me this error, I suppose that on the server side, it does not allow an edit to be made to a table in edition.

CodigoAML = "<Item type='AIT User' action='edit' where=\"id = \'"+sourceID+"\'\"><mp_dias_vac_restantes>"+vacDiasRestantes+"</mp_dias_vac_restantes><mp_dias_vac_apuntadas>"+vac_DiasApuntados+"</mp_dias_vac_apuntadas><mp_dias_vac_disfrutadas>"+vac_DiasDisfrutados+"</mp_dias_vac_disfrutadas></Item>";

var ResultadoEdit = innovator.applyAML("<AML>" + CodigoAML + "</AML>");

I get this error:

I have also tried it by code passing the values through:

var input = getFieldByName("mp_dias_vac_apuntadas");
input.getElementsByTagName("input")[0].value = vac_DiasApuntados;
window.handleItemChange("mp_dias_vac_apuntadas", vac_DiasApuntados);

This code was suggested to me by AngelaP and it works perfectly in forms, but it is Javascript and on the client side.

But it also gives an error, it does not recognize "getFieldByName", nor "getElementsByTagName".

We have Version: Aras Innovator Version 11.0 SP9  Build: 6549

Any suggestions?.

Too many thanks!!!

  • You don't need (and it's not allowed, so you get error) an additional update in the onBeforeUpdate method. Just change the properties of "this".

    this.setProperty("mp_dias_vac_restantes", vacDiasRestantes);
    this.setProperty("mp_dias_vac_apuntadas", vac_DiasApuntados);
    this.setProperty("mp_dias_vac_disfrutadas", vac_DiasDisfrutados);
    return this;

    And more likely you need link you method to onBeforeAdd too.

  • Yes!!, its works!!!!. Thanks.

     Now the problem is that when executing the method before saving the related table, the one below. Since the changes are not saved, they are not applied to the summation. If I press the save button twice, the second time it already applies the changes. Which is logical since the data is not yet saved.

    Another question, to get the counter of the selected days I execute this AML:

    CodigoAML = "<Item type='MP CONTROL PRESENCIA' action='get' returnMode='countOnly'><mp_con_usr>"+sourceID+"</mp_con_usr><mp_tipo_inci>V</mp_tipo_inci></Item>";
    var ResultadoControlP = innovator.applyAML("<AML>"+CodigoAML+"</AML>");
    int vac_DiasDisfrutados = ResultadoControlP.getItemCount();

    Is there a better way to get the data?.

    Too many thanks!!!!

  • If you get your vac_* values using AML query you get the old data as you code run before update. Changes are available as relationships of the "this". But changes only.

    There was a similar question here some time ago. Maybe this help you.

    Update Parent Item when Relationships Tab is Changed

Reply Children