locked
How to get Item oid form particular contact RRS feed

  • Question

  • Hi friends,
                 I want to know How can I get the Item OID from particular contact Item. I tried 

                CEOID oid = 0;
                pContact->get_Oid((long*)&oid);

    But it is not giving me particular record if I edit or delete particular record.

    Regards,
    Ash_21.
    Tuesday, December 15, 2009 11:12 AM

Answers

  • There is no OID until the item has been saved, here's a snippet for bringing a newly created (but not yet saved) contact into the editor, saving it and getting it's OID


    I'm not qualified to say if the approach below is the best or most optimal, just that it works as intended.


    if (pContact)

    {

    IItem* pItem = NULL;

    HRESULT hr = pContact->QueryInterface (__uuidof(IItem), (LPVOID*)&pItem);

    if (SUCCEEDED (hr) && (NULL != pItem))

    {

    if (SUCCEEDED (pItem->Edit (NULL)))

    {

    if (SUCCEEDED (pItem->Save ()))

    {

    pItem->get_Oid ((long*)&oidNewContact);

    }

    }

    pItem->Release ();

    }

    pContact->Release ();

    }

    • Marked as answer by warrentang Monday, December 21, 2009 3:04 AM
    Tuesday, December 15, 2009 4:11 PM

All replies

  • There is no OID until the item has been saved, here's a snippet for bringing a newly created (but not yet saved) contact into the editor, saving it and getting it's OID


    I'm not qualified to say if the approach below is the best or most optimal, just that it works as intended.


    if (pContact)

    {

    IItem* pItem = NULL;

    HRESULT hr = pContact->QueryInterface (__uuidof(IItem), (LPVOID*)&pItem);

    if (SUCCEEDED (hr) && (NULL != pItem))

    {

    if (SUCCEEDED (pItem->Edit (NULL)))

    {

    if (SUCCEEDED (pItem->Save ()))

    {

    pItem->get_Oid ((long*)&oidNewContact);

    }

    }

    pItem->Release ();

    }

    pContact->Release ();

    }

    • Marked as answer by warrentang Monday, December 21, 2009 3:04 AM
    Tuesday, December 15, 2009 4:11 PM
  • Thank you KarenV for your valuable reply.

    I am directly accessing contact database. I got the event when I add,edit or delete any record. Is it necessary to call pItem->Save() on adding & editing an item & call pItem->Remove() when deleting an Item?

    Please answer on this query so that I can be clear on my POOM ideas.

    Regards,
    ash_21

    ash_21, India.
    Wednesday, December 16, 2009 4:53 AM
  • Hello,

    Calling Save on IContact interface when you Add/edit something but for delete you dont need to. That's my experience.

    Thanks
    Arpit Pradhan
    WinCE CODER (If you think my solution help you in some sense do mark my Reply as Answer)
    Wednesday, December 16, 2009 5:48 AM
  • Hello Arpit,
                    I am getting event properly when I add/edit any account. When I am alphabetically store the contacts it's showing me all details properly but when I try to insert any record in between then it is giving me last known value.
                    I am closing POOM once my operation is over & initializing it when I add any new record.
                    How should I get the current contact Item value?
                    Please advise me on this. I am clueless about that.
     
    ash_21, India.
    Wednesday, December 16, 2009 9:43 AM
  • Can you clarify what you mean by getting the "current contact Item value?" 

    No need to close POOM after each operation.  If you are using it multiple times within your app session, just open it once, close when you're all done.

    There is no way to really "insert record in between", it will sort by FileAs typically.
    Thursday, December 17, 2009 7:17 PM