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 - Delete No Related Relationship Item

Hrishikesh - Monday, February 7, 2011 10:10 AM:

 

Hello All,

    I want to delete a No Related Relationship Item through code. I got the No Related Relationship Item ID and Other Properties also, But when i delete the Item it gives the Error as " Body node is not Found ".

   So, How should i delete the No Related Relationship Item.

   Please help....

   Thanking you all.

   Hrishikesh



Brian - Tuesday, February 8, 2011 2:20 AM:

Can I suggest you post your code so we can see what you are doing.

Cheers,

Brian.



Hrishikesh - Wednesday, February 9, 2011 9:09 AM:

Hi Brain,

   When i delete a Project Plan Item ( OnDelete Event ), i also want to delete a Metric Value Item (No Related Relationship item).

The Method is Written on the Project ItemType at ServerEvent. The Sample of Code is as Follow,

Innovator inno = this.getInnovator();
string id = this.getID();

Item proItm = inno.getItemById("project",this.getID());  // Project item

string season = proItm.getProperty("pt_season");   // Property Season

Item seasonName = inno.getItemById("pt_season",season);

 

Item _mtrItm = inno.newItem("Metric","get");  // Metric Item
_mtrItm.setAttribute("select","*");
_mtrItm.setProperty("name","Styles Completed");
Item mtrItm = _mtrItm.apply();

if(mtrItm.getItemCount() ==1)
{
    Item index = mtrItm.getItemByIndex(0);
    Item _mtrRel = inno.newItem("Metric Value","get");  // No Related Relationship ItemType
    _mtrRel.setAttribute("select","*");
    _mtrRel.setProperty("source_id",mtrItm.getID());
    Item mtrRel = _mtrRel.apply();
   
    if(mtrRel.getItemCount()>0)
    {
        for(int i=0;i<mtrRel.getItemCount();i++)
        {
            Item mtrIndex = mtrRel.getItemByIndex(i);
            if(mtrIndex.getProperty("label") == seasonName.getProperty("pt_name"))
            {               
                Item metCompItm = inno.getItemById("Metric Value",mtrIndex.getProperty("id"));

                metCompItm.setAttribute("action","delete");
                metCompItm.apply();
            }
        }
       
    }
}

I get the Metric Value Item "metCompItm", so i want to delete this Item.

Thanking you all.

Hrishikesh



RobMcAveney - Wednesday, February 9, 2011 9:52 AM:

I've never seen that error before so I'm not sure exactly what's happening, but I would suggest at least changing this code:

Item metCompItm = inno.getItemById("Metric Value",mtrIndex.getProperty("id"));

metCompItm.setAttribute("action","delete");
metCompItm.apply();

to this:

Item metCompItm = inno.newIem("Metric Value","delete");
metCompItm.setID(mtrIndex.getID());
metCompItm = metCompItm.apply();

If you already have the id of the Metric Value item there's no need to retrieve it again.  Just delete it using the id.

If you want to optimize the method further, try code like the following:

// Retrieve the Project, the pt_season Item and its season property in a single request
Innovator inno = this.getInnovator();
Item proItm = inno.newItem("Project","get");
proItm.setID(this.getID());
proItm.setAttribute("select","pt_season(season)");
proItm = proItm.apply();
if (proItem.getItemCount() != 1 || proItem.getPropertyItem("pt_season") == null) return inno.newError("Error retrieving project");
string seasonName = proItem.getPropertyItem("pt_season").getProperty("pt_name","?");

// Retrieve all Metric Value items having a label matching the season name and a parent Metric named "Styles Completed"
Item mtrRel = inno.newItem("Metric Value","get");
mtrRel.setProperty("label",seasonName);
Item mtrItm = mtrRel.createPropertyItem("source_id","Metric","get");
mtrItm.setProperty("name","Styles Completed");
mtrRel = mtrRel.apply();

// Loop through the returned Metric Value items and delete each one
for (int i=0; i<mtrRel.getItemCount(); i++)
{
     Item tmpItm = inno.newItem("Metric Value","delete");
     tmpItm.setID(mtrRel.getItemByIndex(i).getID());
     tmpItm = tmpItem.apply();
     if (tmpItm.isError()) return tmpItm;
}



Hrishikesh - Friday, February 11, 2011 4:33 AM:

 

I have Try the above code and Execute but the Same Error is Occur as "Body node is not found".

I have written a method's on Project Server Event  OnAfterAdd and OnAfterUpdate.  In this i am adding the Items and also Update in Metric Value No Related Relationship Item, at this stage i am getting the Correct Result, But when i delete the Metric Value No Related Relationship Item from OnDelete of Project Item the Error Occur as "Body node is not found".

So please any body help me for this problem.

Thanking you all.

Hrishikesh



RobMcAveney - Friday, February 11, 2011 10:54 AM:

Can you be more specific about where this message occurs?  Is there a particular line of code that returns this message?  An error dialog in the client?  I've never seen that error before, but it appears to have something to do with a badly formed XML response (it can't find the /SOAP:Envelope/SOAP:Body tag).  Have you tried stepping through your method in the debugger?  What does your method return?



Hrishikesh - Tuesday, February 15, 2011 2:21 AM:

A small Mistake was done,

I am Returning the "return this" in the method at the End, so the Error was Occur "Body node is not found".

When i changed it to " return inno.newResult(" "); " the Error was solved. Successfully the code is worked and the Metric Value No Related Relationship Item was Deleted.

Rob McAveney your guidance was very Helpful.

Thanking You.

Hrishikesh