Forum Discussion
Hi Dominic,
It looks like you're using the Item res5 to store a collection of items that you're building from your federated data. I believe the issue you're seeing is that the line
Item res5 = this.newItem("MIN_1149_MSF");
is actually adding an empty item to the beginning of this collection of items. You can resolve this issue by including logic like the code below just before the return statement at the end of your method.
Hey Chris, I just noticed that the data returned is duplicated. Any suggestions?
Item qry0 = this.newItem("MIN_1149");
qry0.setAttribute("select","msf");
qry0.setID(this.getProperty("source_id"));
Item res=qry0.apply("get");
string masterpart = res.getProperty("msf");
System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(@"Provider=SQLOLEDB;Data Source=000.00.0.0; Initial Catalog=AA; User ID=cc;Password=pp;");
string sqltext = "select aa,bb,cc,dd from WP where aa = '" + masterpart + "';";
System.Data.OleDb.OleDbCommand com = new System.Data.OleDb.OleDbCommand(sqltext);
com.Connection = myConnection;
myConnection.Open();
System.Data.OleDb.OleDbDataReader myDataReader = com.ExecuteReader();
Item res5 = this.newItem("MIN_1149_MSF");
res5.setID(getNewID());
res5 = res5.apply();
while (myDataReader.Read())
{
Item temp = this.newItem("MIN_1149_MSF1");
temp.setProperty("aa",myDataReader.GetString(0));
temp.setProperty("bb",myDataReader.GetString(1));
temp.setProperty("cc",myDataReader.GetString(2));
temp.setProperty("dd",myDataReader.GetString(3));
res5.appendItem(temp); // Add a new item for each iteration of the loop
};
myConnection.Close();
if ( res5 . isCollection ())
{
res5 . removeItem ( res5 .getItemByIndex (0));
}
return res5;
- christopher_gillis7 years agoCommunity Manager
Hello,
I'm not seeing anything immediately that would indicate why the data would be being duplicated. Can you check if the SQL table you're querying on has duplicate records inside of it?
Chris
- ddidonato7 years agoCreator II
Chris,
Let me start by saying that MIN_1149_MSF is a Federated Item (Relationship)
Within my method, If: “Item temp = this.newItem("MIN_1149_MSF"); “
I get duplicated records.
If I change my method to “Item temp = this.newItem("MIN_1149_MSF1"); “
No duplicates, but I get an error message when saving parent record “[object Object}”. I only get the error if I’m saving while the relationship Tab for “MIN_1149_MSF” is displayed
Thanks
I