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 - populating a Federated property on the Activity2 itemtype

fli - Tuesday, June 28, 2011 9:24 AM:

Hi,
Sadly I can't seem to understand how to use the federated property datatype.
I am trying to populate a federated property (spec_no) on the Activity2 Itemtype.
"spec_no" should be populated with data (name) from the "project" in which it is related.
Am I missing some data I should have made available from a OnBeforeGet event' __?   
if someone would give a short example It would be great !

this is my best try: 
 
server event OnAfterGet____________________________________________

if (this.isEmpty())
  return this;
 
for (int i = 0; i <this.getItemCount(); i++)
{
  Item myItem = this.getItemByIndex(i);
 
//////get project DATA
string myActID = myItem.getProperty("id","");
//
Item myWbsItem = this.newItem("WBS Activity2","get");
myWbsItem.setAttribute("select","source_id,related_id");
myWbsItem.setProperty("related_id",myActID);
myWbsItem = myWbsItem.apply();
 
if (myWbsItem.getItemCount()==1)   {
Item myProjItem = this.newItem("project","get");
myProjItem.setAttribute("select","name,wbs_id");
myProjItem.setProperty("wbs_id",myWbsItem.getProperty("source_id",""));
myProjItem = myProjItem.apply();
}
//--
if (ProjItem.getItemCount()==1)   {
       myItem.setProperty("spec_no",myProjItem.getProperty("name",""));
}
}
return this;
Thank you very much
BR / Christoffer

 



Dave_Rollinson - Thursday, June 30, 2011 7:32 AM:

Christoffer

There are two problems in your Method:

1) The following section:

Item myWbsItem = this.newItem("WBS Activity2","get");
myWbsItem.setAttribute("select","source_id,related_id");
myWbsItem.setProperty("related_id",myActID);
myWbsItem = myWbsItem.apply();
The "select" of "related_id" on "WBS Activity2" will cause a "get" of "Activity2", since you're using this Method as "onAfterGet" for "Activity2" this will cause an infinite loop.
2) This section:
if (myWbsItem.getItemCount()==1)   {
Item myProjItem = this.newItem("project","get");
myProjItem.setAttribute("select","name,wbs_id");
myProjItem.setProperty("wbs_id",myWbsItem.getProperty("source_id",""));
myProjItem = myProjItem.apply();
}
//--
if (ProjItem.getItemCount()==1)   {
       myItem.setProperty("spec_no",myProjItem.getProperty("name",""));
}
The object "ProjItem" is not in context when you try to use it in the "if" statement; move the } to a point after the "if" block.



fli - Thursday, June 30, 2011 9:59 AM:

Hi David,

Thanks alot. tricky one...

Works perfecty.

BR / Christoffer