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 - error creating itemtype in javascript method

tigrao - Thursday, March 3, 2011 8:15 AM:

Hello everyone!
I've got a problem.

I have two and a itemType relatioshipType linking the two.
I have a javascript method and when I run this method
I want to create and relate two itemType.
follow my code below:

var inn = top.aras.newIOMInnovator();

var myItemType = inn.newItem("Grafico Cabecalho","add");

myItemType.setProperty("causafundamental",this.value);

var perm = inn.newItem("Grafico Ishikawa Medidas3","add");

perm.setRelatedItem(myItemType);

document.thisItem.addRelationship(perm);

document.thisItem.apply();

After running the code above are in fact related
itemType both because you can view the tab grid relationship.
But when I try to save gives the following error:
 

"The UPDATE statement conflicted with the FOREIGN KEY constraint

"fk3532". The conflict occurred in database "meubanco", table "innovator.GRAFICO_CABECALHO2", column 'id'. The statement has

been terminated"

 

Help me please.



aknourenko - Monday, March 7, 2011 10:44 AM:

My guess would be that you don't have to explicitly call apply() on the document.thisItem as this is done when you click save.



Santhosh - Tuesday, March 8, 2011 3:37 AM:

Hi tigrao,

Recently I have tried kind of scenario in VB.net and able to create relationship and related item. Please find the below code.

Dim ItemProjBase As Item = myInn.newItem("Project Baseline", "add") 'source Item Type

Dim relationship As Item = ItemProjBase.createRelationship("WBS Elements", "add")  'Relationship Item type

Dim newWBSBaseElement As Item = relationship.createRelatedItem("WBSElementBaseline","add")  'related item type

'set properties for related item
newWBSBaseElement.setProperty("proj_num", project_number)
newWBSBaseElement.setProperty("name",wbs_Item.getItemByIndex(0).getProperty("name"))

'set properties for source item.
ItemProjBase.setProperty("project_number", project_number)
ItemProjBase.setProperty("name", Me.getProperty("name").ToString)
ItemProjBase.apply()

hope this helps

Santhosh



tigrao - Thursday, March 10, 2011 9:15 AM:

Hi friends, thanks

I changed as per the example but still I could not.
when I run the first time works, but the second time gives the same error

code:Dim relationship As Item = Me.createRelationship("Grafico Ishikawa Medidas3", "add") 'Relationship Item type

 

 

 

Dim newWBSBaseElement As Item = relationship.createRelatedItem("Grafico Cabecalho","add") 'related item type

newWBSBaseElement.setProperty("causafundamental", "teste001")

 

 

 

 

//**************************************//**************************************//**********************************//

error:

The UPDATE statement conflicted with the FOREIGN KEY constraint "fk3532". The conflict occurred in database "meubanco",

table "innovator.GRAFICO_CABECALHO2, column "id". The statement has been terminated.