Jump to content

If $var = '' ;==> Help


Recommended Posts

okay, this is what im doing, im use the Active directory UDF's to get information from Active Directory to buil email signatures customized for the user. but i need a way that if a field is blank, sort of "$var = NULL" so skip it. Due to the fact that there is not error code returned by the _AD_GetObjectProperties(), i have to look at every field seperatly

#include<AD.au3>
$adObj_displayName = _AD_GetObjectProperties(@UserName, "displayName")
If $adObj_displayName[0][0] = 0 Then
     $adObj_displayName = ''
Else
     $adObj_displayName = $adObj_displayName[1][1]
EndIf

MsgBox(0, "Display Name", $adObj_displayName)

and i have to do a seperate _AD_GetObjectProperties(@UserName, [$AD_Property]) for each field, because if i did all fields i want at once:

_AD_GetObjectPropertied(@UserName, "displayName, company, department, mail")

and say "mail" was blank, it messes my array index up, or i would do it like this

$adObj = _AD_GetObjectPropertied(@UserName, "displayName, company, department, mail")
$adObj_displayName = $adObj[1][1]
$adObj_company = $adObj[2][1]
[/ _

so anyway, when im formating it, i want it all on seperate lines, but if a field in AD is blank, i don't want it to just be a blank line. so i need some way to format all the $var's together, but if $var = '' Then skip. thanks for any help.

Edited by redLabel
Link to comment
Share on other sites

okay, this is what im doing, im use the Active directory UDF's to get information from Active Directory to buil email signatures customized for the user. but i need a way that if a field is blank, sort of "$var = NULL" so skip it. Due to the fact that there is not error code returned by the _AD_GetObjectProperties(), i have to look at every field seperatly

#include<AD.au3>
$adObj_displayName = _AD_GetObjectProperties(@UserName, "displayName")
If $adObj_displayName[0][0] = 0 Then
     $adObj_displayName = ''
Else
     $adObj_displayName = $adObj_displayName[1][1]
EndIf

MsgBox(0, "Display Name", $adObj_displayName)

and i have to do a seperate _AD_GetObjectProperties(@UserName, [$AD_Property]) for each field, because if i did all fields i want at once:

_AD_GetObjectPropertied(@UserName, "displayName, company, department, mail")

and say "mail" was blank, it messes my array index up, or i would do it like this

$adObj = _AD_GetObjectPropertied(@UserName, "displayName, company, department, mail")
$adObj_displayName = $adObj[1][1]
$adObj_company = $adObj[2][1]
[/ _

so anyway, when im formating it, i want it all on seperate lines, but if a field in AD is blank, i don't want it to just be a blank line. so i need some way to format all the $var's together, but if $var = '' Then skip. thanks for any help.

i tied with the below code and i am able to get the diplay name of the particular user. Are you looking for something else?

#include<AD.au3>

_AD_Open()

$adObj_displayName = _AD_GetObjectProperties(@UserName, "displayName")

If $adObj_displayName[0][0] = 0 Then

$adObj_displayName = ''

Else

$adObj_displayName = $adObj_displayName[1][1]

EndIf

MsgBox(0, "Display Name", $adObj_displayName)

_AD_Close()

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

Yes, i probably wasn't very clear, the "displayName" field, will always work, because, you are a user of AD, but try this field "telephoneNumber". but make sure that that field is blank in AD. and the way i wrote the IF statement, it will still work because if the array, is blank then $var = '', that is my problem. when i format all the fields together

$adObj_formated = $adObj_dispalyName & @LF & $adObj_company & @LF & $adObj_telephoneNumber

MsgBox(0, '' $adObj_formated)

if the $adObj_company is holding the value of '' because it was blank in AD, then the message box will have a blank line between the two othere fields, so im trying to find a way to say if the the $var = '' then skip it in the formating. im think this will have to be a function that each $var passes through, and if it is blank the delete the variable or something.

**I think i have found a way, i will post it soon.

Edited by redLabel
Link to comment
Share on other sites

Okay, it is sort of lengthy, but this works:

#include<AD.au3>

;// Query Active Directory to get the current user's object properties and sets variables

_AD_Open()

$config_file = @ScriptDir & "\Company.Config.ini"
$userName = @UserName

$adObj_company = _AD_GetObjectProperties($userName, "company")
If $adObj_company[0][0] = 0 Then
    $adObj_company = ''
Else
    $adObj_company = $adObj_company[1][1]
EndIf

$adObj_department = _AD_GetObjectProperties($userName, "department")
If $adObj_department[0][0] = 0 Then
    $adObj_department = ''
Else
    $adObj_department = $adObj_department[1][1]
EndIf

$adObj_displayName = _AD_GetObjectProperties($userName, "displayName")
If $adObj_displayName[0][0] = 0 Then
    $adObj_displayName = ''
Else
    $adObj_displayName = $adObj_displayName[1][1]
EndIf

$adObj_mail = _AD_GetObjectProperties($userName, "mail")
If $adObj_mail[0][0] = 0 Then
    $adObj_mail = ''
Else
    $adObj_mail = $adObj_mail[1][1]
EndIf

$adObj_mobile = _AD_GetObjectProperties($userName, "mobile")
If $adObj_mobile[0][0] = 0 Then
    $adObj_mobile = ''
Else
    $adObj_mobile = $adObj_mobile[1][1]
EndIf

$adObj_telephoneNumber = _AD_GetObjectProperties($userName, "telephoneNumber")
If $adObj_telephoneNumber[0][0] = 0 Then
    $adObj_telephoneNumber = ''
Else
    $adObj_telephoneNumber = $adObj_telephoneNumber[1][1]
EndIf

$adObj_title = _AD_GetObjectProperties($userName, "title")
If $adObj_title[0][0] = 0 Then
    $adObj_title = ''
Else
    $adObj_title = $adObj_title[1][1]
EndIf

_AD_Close()


;// Format to single variable for output

If $adObj_displayName <> '' Then $adObj_constants = $adObj_displayName
If $adObj_title <> '' Then $adObj_constants = $adObj_constants & @LF & $adObj_title
If $adObj_mail <> '' Then $adObj_constants = $adObj_constants & @LF & $adObj_mail
If $adObj_telephoneNumber <> '' Then $adObj_constants = $adObj_constants & @LF & $adObj_telephoneNumber & " direct"
If $adObj_mobile <> '' Then $adObj_constants = $adObj_constants & @LF & $adObj_mobile & " mobile"


;// Output

MsgBox(0, '',$adObj_constants)

i used the $userName = @UserName so you can change that value and try it with other users ie $userName = 'jdoe' im open to suggestions for better ways to do this. thanks.

Link to comment
Share on other sites

Couldn't you just create your signature and when finished delete the blank lines?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

It's hard to figure this out without more information. I have tried to recreate the output from the code in post number 4. I'm not sure if it is what you want, or even if it will work. You will have to test it yourself, because I don't have AD.au3, nor the file Company.Config.ini

#include<AD.au3>

;// Query Active Directory to get the current user's object properties

Local $asDetails[7] = ["company","department","displayName","title","mail","telephoneNumber","mobile"]

_AD_Open()

$config_file = @ScriptDir & "\Company.Config.ini"
$userName = @UserName
$adObj_constants = ""

For $i = 2 To 6
    $aTest = _AD_GetObjectProperties($userName, $asDetails[$i])
    If $aTest[0][0] <> 0 Then
        $adObj_constants &= $aTest[1][1]
        If $i < 4 Then
            $adObj_constants &= @LF
        ElseIf $i = 4 Then
            $adObj_constants &= " direct" & @LF
        Else
            $adObj_constants &= " mobile"
        EndIf
    EndIf
Next

_AD_Close()

;// Output

MsgBox(0, '',$adObj_constants)
Edited by czardas
Link to comment
Share on other sites

  • 3 weeks later...

thanks for the help, and sorry i went so long before i seen it, here is my finished code. for it work right, you need a folder in the @ScriptDir called "needed assemblies" and build your "Constants" or "templates" there. for outlook a signature builds three files, an .htm, .rtf, .txt. so i put what i wanted for everyones there, and just move it to @appdata & "\Microsoft\Signatures\*.*" and my script builds the rest. Here it is.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=mail_edit.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Run_Tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include<AD.au3>
#include<File.au3>
#include<GUIConstantsEx.au3>
#include<GuiRichEdit.au3>

;// Query Active Directory to get the current user's object properties and sets variables

_AD_Open()

If @error <> 0 Then
    Exit
EndIf

$adObj_company = _AD_GetObjectProperties(@UserName, 'company')
If $adObj_company[0][0] = 0 Then
    Exit
Else
    $adObj_company = $adObj_company[1][1]
EndIf

$adObj_displayName = _AD_GetObjectProperties(@UserName, 'displayName')
If $adObj_displayName[0][0] <> 0 Then $adObj_displayName = $adObj_displayName[1][1]

$adObj_mail = _AD_GetObjectProperties(@UserName, 'mail')
If $adObj_mail[0][0] <> 0 Then $adObj_mail = $adObj_mail[1][1]

$adObj_mobile = _AD_GetObjectProperties(@UserName, 'mobile')
If $adObj_mobile[0][0] <> 0 Then $adObj_mobile = $adObj_mobile[1][1]

$adObj_telephoneNumber = _AD_GetObjectProperties(@UserName, 'telephoneNumber')
If $adObj_telephoneNumber[0][0] <> 0 Then $adObj_telephoneNumber = $adObj_telephoneNumber[1][1]

$adObj_title = _AD_GetObjectProperties(@UserName, 'title')
If $adObj_title[0][0] <> 0 Then $adObj_title = $adObj_title[1][1]

_AD_Close()


;// Move signature template files from needed assemblies folder to signatures folder, based on return value of $adObj_company

FileCopy(@ScriptDir & '\Needed Assemblies\' & $adObj_company & '\*.*', @AppDataDir & '\Microsoft\Signatures\', 1)


;// Complete '*.txt' file based on fields retuned from active directory

$txtObj_file = @AppDataDir & '\Microsoft\Signatures\' & $adObj_company & '_email_signature.txt'

_FileWriteToLine($txtObj_file, 2, '')
If $adObj_displayName > '' Then _FileWriteToLine($txtObj_file, 2, $adObj_displayName)
If $adObj_mobile > '' Then _FileWriteToLine($txtObj_file, 3, $adObj_mobile & " mobile")
If $adObj_telephoneNumber > '' Then _FileWriteToLine($txtObj_file, 3, $adObj_telephoneNumber & " direct")
If $adObj_mail > '' Then _FileWriteToLine($txtObj_file, 3, $adObj_mail)
If $adObj_title > '' Then _FileWriteToLine($txtObj_file, 3, $adObj_title)


;// Complete '*.htm' file based on fields returned from active directory

$htmObj_file = @AppDataDir & '\Microsoft\Signatures\' & $adObj_company & '_email_signature.htm'

If $adObj_displayName > '' Then _FileWriteToLine($htmObj_file, 2, '<BR/>' & '<strong>' & $adObj_displayName & '</strong>' & '<BR/>')
If $adObj_mobile > '' Then _FileWriteToLine($htmObj_file, 3, $adObj_mobile & " mobile" & '<BR/>')
If $adObj_telephoneNumber > '' Then _FileWriteToLine($htmObj_file, 3, $adObj_telephoneNumber & " direct" & '<BR/>')
If $adObj_mail > '' Then _FileWriteToLine($htmObj_file, 3, '<a href="mailto:' & $adObj_mail & '">' & $adObj_mail & '</a>' & '<BR/>')
If $adObj_title > '' Then _FileWriteToLine($htmObj_file, 3, $adObj_title & '<BR/>')


;// Complete '*.rtf' file based on fields returned from active directory

$rtfObj_file = @AppDataDir & '\Microsoft\Signatures\' & $adObj_company & '_email_signature.rtf'

$frm_main = GUICreate('', 0, 0)
$ctrl_edit = _GUICtrlRichEdit_Create($frm_main, '', 0, 0)

_GUICtrlRichEdit_StreamFromFile($ctrl_edit, $rtfObj_file)

_GUICtrlRichEdit_GotoCharPos($ctrl_edit, 0)
_GUICtrlRichEdit_SetCharAttributes($ctrl_edit, '+bo')

If $adObj_displayName > '' Then _GUICtrlRichEdit_InsertText($ctrl_edit, $adObj_displayName & @LF)
If $adObj_title > '' Then _GUICtrlRichEdit_InsertText($ctrl_edit, $adObj_title & @LF)
If $adObj_mail > '' Then _GUICtrlRichEdit_InsertText($ctrl_edit, $adObj_mail & @LF)
If $adObj_mobile > '' Then _GUICtrlRichEdit_InsertText($ctrl_edit, $adObj_mobile & " mobile" & @LF)
If $adObj_telephoneNumber > '' Then _GUICtrlRichEdit_InsertText($ctrl_edit, $adObj_telephoneNumber & " direct" & @LF)

$xPos = _GUICtrlRichEdit_FindTextInRange($ctrl_edit, $adObj_mail)
_GUICtrlRichEdit_SetSel($ctrl_edit, $xPos[0], $xPos[1])
_GUICtrlRichEdit_SetCharAttributes($ctrl_edit, "+un")
_GUICtrlRichEdit_SetCharAttributes($ctrl_edit, "+li")
_GUICtrlRichEdit_SetCharColor($ctrl_edit, "16711680")
_GUICtrlRichEdit_GotoCharPos($ctrl_edit, 0)

_GUICtrlRichEdit_StreamToFile($ctrl_edit, $rtfObj_file)

GUIDelete($frm_main)

;// Create registry key(s) for default send/reply signature, if not exits

$regObj_outlookVersion = StringRight(RegRead("HKCR\Outlook.Application\CurVer", ""), 2) & '.0'

RegRead("HKCU\Software\Microsoft\Office\" & $regObj_outlookVersion & "\Common\MailSettings", "NewSignature")
If @error = -1 Then
    RegWrite("HKCU\Software\Microsoft\Office\" & $regObj_outlookVersion & "\Common\MailSettings", "NewSignature", "REG_SZ", $adObj_company & "_email_signature")
EndIf

RegRead("HKCU\Software\Microsoft\Office\" & $regObj_outlookVersion & "\Common\MailSettings", "ReplySignature")
If @error = -1 Then
    RegWrite("HKCU\Software\Microsoft\Office\" & $regObj_outlookVersion & "\Common\MailSettings", "ReplySignature", "REG_SZ", $adObj_company & "_email_signature")
EndIf


Exit

may be it will work for otheres as well.

P.S. the files need to be named what ever value is returned from $adObj_company = _AD_GetObjectProperties(). that is why if this returns '' or NULL, it will exit. enjoy.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...