VB script Add contains string (Outlook Contact)

2019 @LWH
2019 @LWH used Ask the Experts™
on
Hi All,

Hope your well,

I have a VB script which is nearly there but just a small part missing.

The script is being configured to delete certain contacts with a particular attribute set. Within that subset of contacts with this particular attribute im also adding some additional logic to not delete all of them e.g.

as an example: I look for contacts with extensionattribute1 set with "SPECIALATTRIBUTE", I then say, if email address 2 is populated DO NOT DELETE, move on to the next. My aim is to delete all of these contacts without an email address 2 set. The bit where im stuck is that I'm also trying not to delete contacts that have a certain domain e.g outlook.com but im not sure on the contains context. My ultimate goal is to look for contacts with a particular attribute, keep the ones that have an Email2address set and if their email1address contains outlook.com and then delkete the rest that do not match these conditions.


Set objRecord = objItem.Find("[Extensionattribute1] = ""SPECIALATTRIBUTE""")

While Not objRecord Is Nothing
      
      If objRecord.Email2Address = "" And objRecord.Email1Address <> "*OUTLOOK.com" Then objRecord.Delete

      Set objRecord = objItem.FindNext

Many Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NorieAnalyst Assistant

Commented:
Try this.
Set objRecord = objItem.Find("[Extensionattribute1] = ""SPECIALATTRIBUTE""")

While Not objRecord Is Nothing
      
      If objRecord.Email2Address = "" And UCase(Right(objRecord.Email1Address, 11))  <> "OUTLOOK.COM" Then objRecord.Delete

      Set objRecord = objItem.FindNext

Open in new window

Author

Commented:
https://www.experts-exchange.com/questions/29161195/VB-script-Add-contains-string-Outlook-Contact.html#a42961024

@norie, Thank you for this. Unfortunately that still ends up with outtlook.com contacts being deleted. Thanks for your help
NorieAnalyst Assistant

Commented:
Try this.
Set objRecord = objItem.Find("[Extensionattribute1] = ""SPECIALATTRIBUTE""")

While Not objRecord Is Nothing
      
     ' delete if Email2Address is empty
      If objRecord.Email2Address = "" Then objRecord.Delete

      ' delete if domain of Email1Address is not 'outlook.com'
      If UCase(Right(objRecord.Email1Address, 11))  <> "OUTLOOK.COM" Then objRecord.Delete

      Set objRecord = objItem.FindNext

Open in new window


Or this.
Set objRecord = objItem.Find("[Extensionattribute1] = ""SPECIALATTRIBUTE""")

While Not objRecord Is Nothing
      
      If objRecord.Email2Address = "" Or UCase(Right(objRecord.Email1Address, 11))  <> "OUTLOOK.COM" Then objRecord.Delete

      Set objRecord = objItem.FindNext

Open in new window

Distinguished Expert 2017

Commented:
Can email addresses be null?  If so, then checking for a ZLS will not return true.  "" is NOT the same as Null.
1. To check either empty string or not outlook you need OR, not AND
2. VBScript doesn't have LIKE operator, neither work with wildcards (e.g. *OUTLOOK.com). Use InStr function instead.
If objRecord.Email2Address = "" OR InStr(1, objRecord.Email1Address, "@outlook.com", 1) = 0 Then
    objRecord.Delete
End If
' Last "1" is vbTextCompare, means ignore case

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial