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 - Adding a Relationship between two Existing Items

markW - Tuesday, May 15, 2007 6:57 PM:

Just trying to do something which I would think would be simple.  I have two existing item instances and want to create the relationship between them.  My javascript is below and then following is the XML from the console.  Basically the XML shows just the first item 3 times, which is confusing.  I have tested the "get" portions for the two existing items on their own and they both work.  So somehow it seems my portion for making the relationship is wrong.  I also built the equivalent query in AML and tried that, it produced the same result.

 Can anyone suggest what is wrong?

Mark

 

var innovator = new Innovator();
var ideaitem = innovator.newItem("Idea_P2","get");
ideaitem.setProperty("idea_name","3rd Idea");

var ideadis = new Item("Idea_to_Distribution_P2","add");

var disitem = new Item("Idea_Asses_Distribution_P2","get");
disitem.setProperty("idea_assess_distribution_p2_name","3rd Idea");

ideadis.setRelatedItem(disitem);
ideaitem.addRelationship(ideadis);

var result = ideaitem.apply();

writeResults(result.dom.xml);

----------------------------------------
-<Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-<Body>
-<Result>
-<Item type="Idea_P2
" typeId="561EB972B2234241B37913B4D72646D4
" id="B5555DF5816D4E2BB468DE09BE8799D4
" page="1
" pagemax="1
" itemmax="4
">
<history_id keyed_name="4BCB3E2D1BAB44ECAEEED567F03412B9
" type="History Container
">4BCB3E2D1BAB44ECAEEED567F03412B9
</history_id>
<permission_id keyed_name="World Can Get
" type="Permission
">93AB06D37FC84328A314324DC45DB574
</permission_id>
<new_version>0
</new_version>
<config_id keyed_name="3rd Idea 999aaa
" type="Idea_P2
">B5555DF5816D4E2BB468DE09BE8799D4
</config_id>
<idea_country>India
</idea_country>
<major_rev>A
</major_rev>
<created_by_id keyed_name="Innovator Admin
" type="User
">30B991F927274FA3829655F50C99472E
</created_by_id>
<idea_description>fff
</idea_description>
<is_released>0
</is_released>
<idea_decision_date>05/16/2007
</idea_decision_date>
<idea_owner>ccc
</idea_owner>
<keyed_name>3rd Idea 999aaa
</keyed_name>
<current_state name="Idea Created
" keyed_name="Idea Created
" type="Life Cycle State
">51E6AD8413214A478B2A4E4E7BEE85A9
</current_state>
<id keyed_name="3rd Idea 999aaa
" type="Idea_P2
">B5555DF5816D4E2BB468DE09BE8799D4
</id>
<idea_operator>Wireless Opco1
</idea_operator>
<created_on>05/11/2007 10:57:28 PM
</created_on>
<generation>1
</generation>
<modified_on>05/11/2007 10:57:28 PM
</modified_on>
<idea_tech_platform>UMTS
</idea_tech_platform>
<product_type>New Product
</product_type>
<idea_decision_status>Under Review
</idea_decision_status>
<idea_pay_method>Subscription
</idea_pay_method>
<idea_orig_subs>ccc
</idea_orig_subs>
<is_current>0
</is_current>
<state>Idea Created
</state>
<not_lockable>0
</not_lockable>
<idea_bill_method>Charge Per Time Period
</idea_bill_method>
<modified_by_id keyed_name="Innovator Admin
" type="User
">30B991F927274FA3829655F50C99472E
</modified_by_id>
<idea_srvctype>Voice
</idea_srvctype>
<idea_mkt>Mumbai
</idea_mkt>
<idea_name>3rd Idea
</idea_name>
<idea_id>999aaa
</idea_id>
</Item>
-<Item type="Idea_P2
" typeId="561EB972B2234241B37913B4D72646D4
" id="64CFC1FA6AF44FC29D197C82FD48597F
" page="1
" pagemax="1
" itemmax="4
">
<history_id keyed_name="4BCB3E2D1BAB44ECAEEED567F03412B9
" type="History Container
">4BCB3E2D1BAB44ECAEEED567F03412B9
</history_id>
<permission_id keyed_name="World Can Get
" type="Permission
">93AB06D37FC84328A314324DC45DB574
</permission_id>
<new_version>0
</new_version>
<config_id keyed_name="3rd Idea 999aaa
" type="Idea_P2
">B5555DF5816D4E2BB468DE09BE8799D4
</config_id>
<idea_country>India
</idea_country>
<major_rev>A
</major_rev>
<created_by_id keyed_name="Innovator Admin
" type="User
">30B991F927274FA3829655F50C99472E
</created_by_id>
<idea_description>fff
</idea_description>
<is_released>0
</is_released>
<idea_decision_date>05/16/2007
</idea_decision_date>
<idea_owner>ccc
</idea_owner>
<keyed_name>3rd Idea 999aaa
</keyed_name>
<current_state name="Idea Created
" keyed_name="Idea Created
" type="Life Cycle State
">51E6AD8413214A478B2A4E4E7BEE85A9
</current_state>
<id keyed_name="3rd Idea 999aaa
" type="Idea_P2
">64CFC1FA6AF44FC29D197C82FD48597F
</id>
<idea_operator>Wireless Opco1
</idea_operator>
<created_on>05/11/2007 10:57:28 PM
</created_on>
<generation>2
</generation>
<modified_on>05/15/2007 08:15:10 PM
</modified_on>
<idea_tech_platform>UMTS
</idea_tech_platform>
<product_type>New Product
</product_type>
<idea_decision_status>Under Review
</idea_decision_status>
<idea_pay_method>Subscription
</idea_pay_method>
<idea_orig_subs>ccc
</idea_orig_subs>
<is_current>0
</is_current>
<state>Idea Created
</state>
<not_lockable>0
</not_lockable>
<idea_bill_method>Charge Per Time Period
</idea_bill_method>
<modified_by_id keyed_name="Innovator Admin
" type="User
">30B991F927274FA3829655F50C99472E
</modified_by_id>
<idea_srvctype>Voice
</idea_srvctype>
<idea_mkt>Mumbai
</idea_mkt>
<idea_name>3rd Idea
</idea_name>
<idea_id>999aaa
</idea_id>
</Item>
-<Item type="Idea_P2
" typeId="561EB972B2234241B37913B4D72646D4
" id="A9C51B0CF5034A92B06B56150DB406E5
" page="1
" pagemax="1
" itemmax="4
">
<history_id keyed_name="4BCB3E2D1BAB44ECAEEED567F03412B9
" type="History Container
">4BCB3E2D1BAB44ECAEEED567F03412B9
</history_id>
<permission_id keyed_name="World Can Get
" type="Permission
">93AB06D37FC84328A314324DC45DB574
</permission_id>
<new_version>0
</new_version>
<config_id keyed_name="3rd Idea 999aaa
" type="Idea_P2
">B5555DF5816D4E2BB468DE09BE8799D4
</config_id>
<idea_country>India
</idea_country>
<major_rev>A
</major_rev>
<created_by_id keyed_name="Innovator Admin
" type="User
">30B991F927274FA3829655F50C99472E
</created_by_id>
<idea_description>fff
</idea_description>
<is_released>0
</is_released>
<idea_decision_date>05/16/2007
</idea_decision_date>
<idea_owner>ccc
</idea_owner>
<keyed_name>3rd Idea 999aaa
</keyed_name>
<current_state name="Idea Created
" keyed_name="Idea Created
" type="Life Cycle State
">51E6AD8413214A478B2A4E4E7BEE85A9
</current_state>
<id keyed_name="3rd Idea 999aaa
" type="Idea_P2
">A9C51B0CF5034A92B06B56150DB406E5
</id>
<idea_operator>Wireless Opco1
</idea_operator>
<created_on>05/11/2007 10:57:28 PM
</created_on>
<generation>3
</generation>
<modified_on>05/15/2007 11:11:55 PM
</modified_on>
<idea_tech_platform>UMTS
</idea_tech_platform>
<product_type>New Product
</product_type>
<idea_decision_status>Under Review
</idea_decision_status>
<idea_pay_method>Subscription
</idea_pay_method>
<idea_orig_subs>ccc
</idea_orig_subs>
<is_current>0
</is_current>
<state>Idea Created
</state>
<not_lockable>0
</not_lockable>
<idea_bill_method>Charge Per Time Period
</idea_bill_method>
<modified_by_id keyed_name="Innovator Admin
" type="User
">30B991F927274FA3829655F50C99472E
</modified_by_id>
<idea_srvctype>Voice
</idea_srvctype>
<idea_mkt>Mumbai
</idea_mkt>
<idea_name>3rd Idea
</idea_name>
<idea_id>999aaa
</idea_id>
</Item>
-<Item type="Idea_P2
" typeId="561EB972B2234241B37913B4D72646D4
" id="20EBE9ADC0B740D38DBF0069E4702AC9
" page="1
" pagemax="1
" itemmax="4
">
<history_id keyed_name="4BCB3E2D1BAB44ECAEEED567F03412B9
" type="History Container
">4BCB3E2D1BAB44ECAEEED567F03412B9
</history_id>
<permission_id keyed_name="World Can Get
" type="Permission
">93AB06D37FC84328A314324DC45DB574
</permission_id>
<new_version>0
</new_version>
<config_id keyed_name="3rd Idea 999aaa
" type="Idea_P2
">B5555DF5816D4E2BB468DE09BE8799D4
</config_id>
<idea_country>India
</idea_country>
<major_rev>A
</major_rev>
<created_by_id keyed_name="Innovator Admin
" type="User
">30B991F927274FA3829655F50C99472E
</created_by_id>
<idea_description>fff
</idea_description>
<is_released>0
</is_released>
<idea_decision_date>05/16/2007
</idea_decision_date>
<idea_owner>ccc
</idea_owner>
<keyed_name>3rd Idea 999aaa
</keyed_name>
<current_state name="Idea Created
" keyed_name="Idea Created
" type="Life Cycle State
">51E6AD8413214A478B2A4E4E7BEE85A9
</current_state>
<id keyed_name="3rd Idea 999aaa
" type="Idea_P2
">20EBE9ADC0B740D38DBF0069E4702AC9
</id>
<idea_operator>Wireless Opco1
</idea_operator>
<created_on>05/11/2007 10:57:28 PM
</created_on>
<generation>4
</generation>
<modified_on>05/15/2007 11:49:54 PM
</modified_on>
<idea_tech_platform>UMTS
</idea_tech_platform>
<product_type>New Product
</product_type>
<idea_decision_status>Under Review
</idea_decision_status>
<idea_pay_method>Subscription
</idea_pay_method>
<idea_orig_subs>ccc
</idea_orig_subs>
<is_current>1
</is_current>
<state>Idea Created
</state>
<not_lockable>0
</not_lockable>
<idea_bill_method>Charge Per Time Period
</idea_bill_method>
<modified_by_id keyed_name="Innovator Admin
" type="User
">30B991F927274FA3829655F50C99472E
</modified_by_id>
<idea_srvctype>Voice
</idea_srvctype>
<idea_mkt>Mumbai
</idea_mkt>
<idea_name>3rd Idea
</idea_name>
<idea_id>999aaa
</idea_id>
</Item>
</Result>
</Body>
</Envelope>

 

---------------------------------------

 



RobMcAveney - Tuesday, May 15, 2007 8:32 PM:

Hi Mark -

The request you're sending isn't quite right, but you're definitely correct that the response is odd.  It's actually returning all generations of the Idea_P2 item (note that id and generation vary in the returned item).  I'll file a bug report on this one.

You need to use action="edit" on the parent item to make this work in this form. You also need to uniquely identify the parent item, since there are multiple generations out there.  You can do a query to get the id, then use that id to edit.  Alternatively, you can use the where attribute to get the current version of the parent item.  For example:
 

var innovator = new Innovator();
var ideaitem = innovator.newItem("Idea_P2","edit");
ideaitem.setAttribute("where","[IDEA_P2].idea_name='3rd Idea' and [IDEA_P2].is_current='1'");
...

Rob

 

 



markW - Wednesday, May 16, 2007 4:34 AM:

Thanks Rob, I am glad I posted, answer is simple but it would have probably taken me days to realize it.  What you say makes sense I will try it this evening, I think it will resolve my issue.