Forum Discussion

Harald_Korneliussen's avatar
8 months ago

Item.apply overwriting action, has it always done this?

After upgrading from version 12 to 31, we started getting an error when saving a certain custom datastructure, developed for us by Minerva back in the day:

Failed to execute 'serializeToString' on 'XMLSerializer': parameter 1 is not of type 'Node'.

From what I can tell, this happens because Minerva's old code calls an action directly on the document.thisItem object

    var output = document.thisItem.apply("VE_GetCopyTreeGridHeader");
which "pollutes" document.thisItem with that action. When later hitting save, it calls this function instead of doing whatever it ordinarily would (probably a get action), resulting in the error. I observe that if I change the action to "get", it gets rid of the error message and saves any changes in the object itself, but not in a related items treegrid associated with it. If I change the Iaction to "update", it saves everything correctly the way it used to do in version 12.
I see that the docs on item apply says that it overwrites the action, but if it always did that, how did this code ever work? (By the way, that .apply() overwrites the action is an error-prone side effect which I can't see any good reason for)

1 Reply

  • When you upgrade via the regular Aras upgrade service, this one is an Aras problem, not a YOU problem :).

    I right now would expect that the error happens in the Method "VE_GetCopyTreeGridHeader" itself. When you come from I12 and upgrade to I31, it´s probably a typical issue caused by obsolete functions. Typical something .NET Core related, but in your case the error message doesn´t match so I can´t tell.

    document.thisItem.apply is nothing unusual. Instead of "get","edit",etc. you do something custom. Very often the custom code might do something very similar like regular edits and gets, but does something additional. 

    When I look at my own code for something comparable I found one Method that use this exact technique for replacement of the regular "promote" button. The Method does some validation, opens a custom promote Form, than does the original "promote" action and a few additional relationship edits and returns the same item that would have been returned when doing a regular promote.