2019 @LWH
asked on
VB script Add contains string (Outlook Contact)
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("[Extensionat tribute1] = ""SPECIALATTRIBUTE""")
While Not objRecord Is Nothing
If objRecord.Email2Address = "" And objRecord.Email1Address <> "*OUTLOOK.com" Then objRecord.Delete
Set objRecord = objItem.FindNext
Many Thanks.
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("[Extensionat
While Not objRecord Is Nothing
If objRecord.Email2Address = "" And objRecord.Email1Address <> "*OUTLOOK.com" Then objRecord.Delete
Set objRecord = objItem.FindNext
Many Thanks.
ASKER
https://www.experts-exchange.com/questions/29161195/VB-script-Add-contains-string-Outlook-Contact.html?anchorAnswerId=42961024#a42961024
@norie, Thank you for this. Unfortunately that still ends up with outtlook.com contacts being deleted. Thanks for your help
@norie, Thank you for this. Unfortunately that still ends up with outtlook.com contacts being deleted. Thanks for your help
Try this.
Or 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
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
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.
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
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window