DK@Aras - Tuesday, February 11, 2014 7:40 AM:
Hi,
I have 2 itemtype(A and B) which are related. and Form looks like below:
A itemtype
------------------------------------------------------------------------------
A Itemtype Properties
-----------------------------------------------------------------------------
-----{Other Relationship} | {B Itemtype} | --------------------------
Now instead of using "Pick related" option, i want to set value in "B Itemtype" Grid with my custom logic.
I tried setrelationship() and addrelationship() methods but it is not displaying anything in the "B itemtype" relationship grid.
Kindly guide me how i can achieve it using server side, since i am using SQLQuery to get my data. Also let me know if i have use specific event to achieve this functionality.
Thank you in advance !!
Harsha - Thursday, February 13, 2014 12:23 AM:
DK, here is an example to add a Related Item using Server Method.You can use OnBeforeAdd.
Innovator inn = this.getInnovator();
string ItemId = this.getID();
//Get Related Item
Item relatedItem = inn.newItem("RelatedItemName","get");
relatedItem.setAttribute("where","[RELATEDITEMNAME].item_number = 'ITEM-1000' "); //example query to get an Item.
Item result = relatedItem.Apply();
string relatedItem_id = result.getID();
//Add Relationship
Item relItem = inn.newItem("RelationshipName","add")
relItem.setProperty("source_id",ItemId);
relItem.setProperty("related_id",relatedItem_id);
relItem = relltem.Apply();
Harsha.
DK@Aras - Thursday, February 13, 2014 1:33 AM:
Hi Harsha,
Thank you for your response !!
I tried the sample code you have with the "onBeforeAdd" event but i am getting error while saving as "The multi-part identifier "[RELATEDITEMNAME].item_number" could not be bound."
In my relationship, i have other relationship as well which is related to "Poly" item type. Is this error because of that ??
Kindly let me know, if i have to made any changes to make above code work.
Thank you in advance !!
Harsha - Thursday, February 13, 2014 9:12 AM:
Hi,
[RELATEDITEMNAME] should be replaced with you RelatedItem's ItemType name. Did you do that? 'RelateditemName' is just a sample name I used to give you a hint to add your Related ItemType name there.
DK@Aras - Thursday, February 13, 2014 11:58 PM:
Thank you for quick reply !!
Yes harsha, i had replaced relateditemname and relationshipname with thier respective value but i was getting error as i mentioned.
Harsha - Friday, February 14, 2014 12:12 AM:
DK, Please check that your [RELATEDITEMNAME] should not have any spaces, for ex: If Item Type2 is your related item name then use it as [ITEM_TYPE2] while querying. All the spaces should be replaced with underscores(Only in case of a query).
DK@Aras - Friday, February 14, 2014 1:53 AM:
Hi Harsha,
It seems that above error was coming because of "_" was missing in query. But now i am getting other error "AddItem_Implementation_AddAccessDenied" "Access denied to add RelationshipName, can_update is not allowed for source.".
I have verified permission for source itemtype, related itemtype and relationship as well but still getting the error. Also, i have tried to use above code by logging in "root" user but similar error.
Kindly provide if any suggestion/guidance to overcome this issue.
Thank you again !!