Forum Discussion

angela's avatar
angela
Catalyst II
1 month ago

How to reset an unique item property FAST on item copy / Save As

Hi community,

I have a simple ItemType with an item property that links to a Part. The item property is "unique" AND "required". User shall be able to copy the item via Save As. 

When using Save-As to copy the item, I get the expected error:

Violation of UNIQUE KEY constraint "UN7732". A duplicate key cannot be inserted into the innovator.ITsNotAI object. The duplicate key value is (123456....).

Something like this is an onBeforeCopy event unfortunately doesn´t work:

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

I know tons of complex over-engineered solutions to address the problem. E.g. don´t use the unique attribute and use a Method for uniqueness check and "onAfterCopy" for item edit. Or use a custom CUI copy button....
But somehow all these idea mean more Methods for a trivial problem.

Isn´t there a way to address this task with ONE simple unique "onBeforeCopy" Method?

From my POV the main obstacle is that Innovator automatically saves the item after copy. But I don´t need the copied item to be saved instantly. Why not just display it as  new temporary new item to the user?

I did some attempts to overwrite the default onBeforeCopy logic to simulate a temporary Part. But Innovator doesn´t honor my current ideas yet. :)

Does anyone has an idea to address this task in a very simple way?
Is it possible to prevent that Aras automatically saves the item after copy?

Thanks!

Angela

5 Replies

  • Hi Michael,

    yes onBeforeAdd would have been a useful solution. Unfortunately I have an unique "item property" that requires an id based item. So the "Copy of" trick didn´t work here. 

    But I found a solution: Aras it self used a CUI replacement for a custom "Save As" button in the query builder. So CUI seems the way to go. But I used a different approach in the Method than the original Aras code. I discovered that the native "copyItemEx" function includes soem additional parameters. One of them allow us to display a copied item to the user WITHOUT saving it! Perfect solution!

    BTW: I currently don´t get any emails when somebody answers my posts. 

  • Hello Angela,
    We made a custom Save as Action that display a dialog window to the user to enter values for properties that are read Only True after add and Required True.
    As an example, Part Number is read only in Preliminary but is mandatory, so Part Number must be set beforeAdd, this dialog window allow to manually specify and replace the value "copy of Part 0001" by "Part 0011".
    Regards
    Michael

  • There is no easy way to meet your requirements.

    Using a trigger with a database type of INSTEAD OF INSERT to check for duplicate values and then set new values for them should solve your problem.

  • Hello
    I don't know why my previous answer has been deleted.
    We overcame the same problem just by showing the user a dialog window to enter new values before SaveAs is apply
    on action save as fetch Item Number > show dialog window> User set new Item number in dialog > parse values to method that copy
    like this, the property that is unique and read only has been set to new value beforeAdd.
    regards
    Michael

    • eli_donahue's avatar
      eli_donahue
      Community Manager

      Hi Michael, it looks like your previous message got caught in the system's automated spam filter. I'm not sure why, because it looks fine to me. I've released it, so it will now appear. Let me know if you run into this issue again!