Ax2009 Event Processing Error

I have a customer that gets a error every time the EventJobCUD-batch (Change Based Events) runs. They got the following error:

After some reseach I found out that when 2 fields are changed at the same time, you go several times through the listChangedFieldsEnumerator (location ClassesEventProcessorCUDprocessUpdate)

1
2
3
4
5
6
7
8
9
while (listChangedFieldsEnumerator.moveNext())
{
    // In this simple case we use the new and the original changed field value as
    // recorded at event detection time:
    [thisFieldId, changedFieldValue, origChangedFieldValue] = listChangedFieldsEnumerator.current();
 
    if (rule.AlertFieldId == thisFieldId)
        break;
}

The code underneed simulates the same situation in a small job:

1
2
3
4
5
6
7
8
9
static void Job5(Args _args)
{
    anytype any;
    ;
    any = ABC::A;
 
    // next line will throw a error
    any = BatchStatus::Canceled;
}

And here we get the basic same error “Error executing code: Wrong argument types in variable assignment.”

I modified the code so the anytype is assigned only when the field is correct:

1
2
3
4
5
6
7
8
9
10
11
12
while (listChangedFieldsEnumerator.moveNext())
{
    // In this simple case we use the new and the original changed field value as
    // recorded at event detection time:
    thisFieldId = conpeek(listChangedFieldsEnumerator.current(), 1);
 
    if (rule.AlertFieldId == thisFieldId)
    {
        [thisFieldId, changedFieldValue, origChangedFieldValue] = listChangedFieldsEnumerator.current();
        break;
    }
}
  1. Saelen Kenny says:

    Hi jeroen,

    Nice one, but important to remark in the post : This is in fact the behavior of an anyType. Once it has been assigned, you cannot assign other values that have a different type. (Event when the base type of the type is the same) Both are enums, but the typeId in Dynamics is different.

    See the following article and extract on MSDN:

    http://msdn.microsoft.com/en-us/library/aa853001.aspx

    “If anytype is used as a variable, you must assign a value to it before it can be used or you will get a run-time error. After you have assigned a value to it, you cannot convert it to another data type.”

    regards,
    Kenny

  2. […] reading…. SOURCE: http://www.doens.be By Jeroen Doens on February 22, 2012   /   Development, Dynamics Ax   /   […]

Comments are closed.