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 - Create new item, open form, get primary key error on Save

Pat Madigan - Tuesday, October 25, 2011 5:10 PM:

I have a Javascript method in Aras 9.1 that clones an item (most values of the item, anyway) and opens up the item in a form.  This is executed from a button on a form, for the original (parent) item.  This works fine, but if the user hits Save on the newly opened form, Aras says that the record already exists, and the detail shows a primary key constraint error.  However, if they close the form and reopen it, it will work fine.

Here is a simplified version of the method:

var a = top.aras;
var inn = a.newIOMInnovator();
var oldItem=document.thisItem.getProperty("id");

var newItem = document.thisItem.newItem("Item_Type_Being_Copied","add");
newItem.apply();

newItem.lockItem();

top.aras.uiShowItemEx(newItem.node,undefined,true);

 

Any idea what I'm doing wrong?

thanks,

Pat



Pat Madigan - Tuesday, October 25, 2011 6:22 PM:

I changed my code to use the clone() method, and that seems to work fine.  It's a much better way to copy an item, and there are no errors when I try to save it.  This is pretty much the whole method, about all that I do is set the parent_id, which is my property for tracking where the item was copied from.  There's still a bug with the newly opened form not showing the new ID (until you close and re-open it).

var a = top.aras;
var inn = a.newIOMInnovator();
var oldItem=document.thisItem;

var newItem = document.thisItem.clone(true);
newItem.setProperty("parent_id",oldItem.getProperty("id"));
newItem.setNewID();

newItem.apply();

newItem.lockItem();

top.aras.uiShowItemEx(newItem.node,undefined,true);

return newItem;

Pat