none
What does myItem.Links.Add Item Link to? RRS feed

  • Question

  • If Item = the current contact and myItem is a task, what task properties of these two objects is actually linked using:

    myItem.Links.Add Item

    There's no links property in the ObjectExplorer for either item.

    In other words, I'm trying to loop through all of the tasks linked to a contact, but cannot identify the key element that's actually linked. 

    Thanks.

    Tuesday, July 23, 2013 7:20 PM

Answers

  • I ended up using the following which seems to work fine as long as the task hasn't been assigned to more than one person.

    if myitems(I).Recipients.Item(1).Name = ContactName Then . . . .


    Ross

    • Marked as answer by T3mplar Wednesday, July 24, 2013 12:45 AM
    Wednesday, July 24, 2013 12:45 AM
  • Here's what I ended up doing.

    Added:

    dim Recipients
    ....
    If I = 1 to NumItems
    
    Set Recipients = myItems(I).Recipients
    
    If Recipients.Count > 0 Then
    
    If myItems(I).Recipients.Item(1).Name = Contactname Then
    ....
    End IF
    End IF
    
    Next
    


    Ross

    • Marked as answer by T3mplar Wednesday, July 24, 2013 7:00 PM
    Wednesday, July 24, 2013 6:43 PM

All replies

  • Support for Links has been deprecated in Outlook 2013 - do not use it anymore!

    What's new for Outlook 2013 developers
    http://msdn.microsoft.com/en-us/library/jj228679.aspx

    If you must use this functionality, you can still use it with Redemption.


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, July 23, 2013 7:28 PM
    Moderator
  • I found it!

    myItem.Owner



    Ross

    Tuesday, July 23, 2013 7:30 PM
  • Roger that.  In this case, I'm using 2007.

    Thanks.


    Ross

    Tuesday, July 23, 2013 7:36 PM
  • Owner would refer to the creator of the task or whoever accepted a task assignment.

    Each item has a Links collection. Iterating that returns each Link object, which can only be a contact item. Links.Item(x).Item would return the linked contact from the task.


    Ken Slovak MVP - Outlook

    Tuesday, July 23, 2013 8:11 PM
    Moderator
  • Yes, I found out the hard way that Owner was wrong.

    Using the contactitem.links.item(x).item cause Outlook to crash.

    When I try to run this basic code:

    Dim x  
    Dim msg
    Dim myItems
    Dim myItem
    dim myLinks
    
    Set olns = Item.Application.GetNameSpace("MAPI")
    Set MyFolder = olns.GetDefaultFolder(13)
    NumItems = MyFolder.Items.Count
    Set myItems = MyFolder.Items 
    
    For each myItem in myItems
    	If TypeName(myItems.Item(x)) = "TaskItem" Then 
    		Set myLinks = myItem.Links 
    		Msg = myItem.Subject & " has " & myLinks.Count & " links." 
    		msgbox msg
    	End If 
    	x = x + 1
    next
    

    I get an Object Required error on myLinks.Count.

    ???


    Ross

    Tuesday, July 23, 2013 11:55 PM
  • Did I mention I'm having to do this in vbscript?

    Ross

    Wednesday, July 24, 2013 12:03 AM
  • I ended up using the following which seems to work fine as long as the task hasn't been assigned to more than one person.

    if myitems(I).Recipients.Item(1).Name = ContactName Then . . . .


    Ross

    • Marked as answer by T3mplar Wednesday, July 24, 2013 12:45 AM
    Wednesday, July 24, 2013 12:45 AM
  • VBScript is irrelevant.

    In the Item(x) I intended that x be replaced with an index value. Sorry that wasn't clear to you. So to get the first Link you'd use Item(1) instead of Item(x).

    ContactName only works if there is one link, as you mentioned. It's better to iterate the Links collection, or at least to check Links.Count before using that method.


    Ken Slovak MVP - Outlook

    Wednesday, July 24, 2013 2:09 PM
    Moderator
  • Thanks.  I understood the x significance.

    The Links.Count always returns an 'object required' error making it useless.

    I'm trying to use the recipients instead.  I'm able to loop through all of the task to see if the contactname = recipients.item(1).name.

    I'd rather restrict the items using Set myItems = myFolder.Items.Restrict(.... but I can't figure out the syntax exactly.

    ?)  .Restrict([Recipients.Item(1).Name = '" & ContactName & "'" 

    Any help would be greatly appreciated.


    Ross

    Wednesday, July 24, 2013 6:11 PM
  • Actually, perhaps Contacts will work better?

    Ross

    Wednesday, July 24, 2013 6:17 PM
  • Sorry, I misread the Restrict Method details.  Contacts is excluded.  So I guess I'm back to Recipients?

    Ross

    Wednesday, July 24, 2013 6:20 PM
  • Neither Contacts nor ContactNames can be used in a filter or restriction. That's documented in the Object Browser Help on Items.Restrict.

    I don't see how Links.Count can return an exception, except if it was used on Outlook 2013. Even if there are no links at all, items.Links.Count will return 0. As long as your "item" reference is valid there should be no exception when accessing Links or Links.Count.


    Ken Slovak MVP - Outlook

    Wednesday, July 24, 2013 6:35 PM
    Moderator
  • I'd get Links working, that's the way to go. 

    Recipient.Name should work in most cases but it's not guaranteed to produce the identical results as Contacts unless the recipients are all in Contacts (not the GAL) and use the same formats for naming in both cases.


    Ken Slovak MVP - Outlook

    Wednesday, July 24, 2013 6:37 PM
    Moderator
  • Here's what I ended up doing.

    Added:

    dim Recipients
    ....
    If I = 1 to NumItems
    
    Set Recipients = myItems(I).Recipients
    
    If Recipients.Count > 0 Then
    
    If myItems(I).Recipients.Item(1).Name = Contactname Then
    ....
    End IF
    End IF
    
    Next
    


    Ross

    • Marked as answer by T3mplar Wednesday, July 24, 2013 7:00 PM
    Wednesday, July 24, 2013 6:43 PM