Jump to content

Remove line if ad field empty


jackr57
 Share

Recommended Posts

Hi

I have a working outlook signature script, that pulls data from active directory. I am just having a problem with fields that are optional.

 

Func regsig ()

FileInstall("sig.htm", $sigpath & "\tmp.htm",1)
$filename1 = $sigpath & "\tmp.htm"
_ReplaceStringInFile($filename1,"namenamename",$fullname)
_ReplaceStringInFile($filename1,"emailemailemail","<a href='mailto:"& $emailaddress &"'>" & $emailaddress & "</a>")
_ReplaceStringInFile($filename1,"titletitletitle",$title)
_ReplaceStringInFile($filename1,"offnumoffnumoffnum",$officenumber)
_ReplaceStringInFile($filename1,"faxfaxfax",$faxnumber)
_ReplaceStringInFile($filename1,"extensionAttribute1extensionAttribute1extensionAttribute1",$extensionAttribute1)
If $mobilenumber <>"" Then
    _ReplaceStringInFile($filename1,"mobilemobilemobile", "Mobile: " & $mobilenumber)
Else
    _FileWriteToLine($filename1, 13, "", 1)
EndIf
If $mainnumber <>"" Then
    _ReplaceStringInFile($filename1,"mobile2mobile2mobile2", "Mobile: " & $mainnumber)
Else
    _FileWriteToLine($filename1, 14, "", 1)
EndIf
If $webpage <>"" Then
    _ReplaceStringInFile($filename1,"webpagewebpagewebpage","<a href='"& $webpage &"'>" & $webpage & "</a>")
Else
    _FileWriteToLine($filename1, 16, "", 1)
EndIf
FileCopy($filename1,$sigpath & "\" & $sightm,1)
EndFunc

As you can see here

_FileWriteToLine($filename1, 13, "", 1)

This works great but the problem is that the line numbers change when certain fields are removed preventing this line removal method from working.

If the fields in AD are blank and the else statement is not there, then it simply writes "mobilemobilemobile" to the line as that is what it is in the template file. Ideally I would need a way to use _replacestringinfile in such a way that removes the line when the active directory field that is mapped to that variable is empty.

Else
_ReplaceStringInFile($filename1,"mobile2mobile2mobile2","")

This results in an empty line in the signature which is better than mobile2mobile2mobile2. but ideally would like to remove the line.

Edited by jackr57
Link to comment
Share on other sites

I also could not remove empty lines but you can create a new one without them.

#include <File.au3>

$original_file = @ScriptDir & "\test.ini"
$new_file = @ScriptDir & "\test new.ini"
$count_line = _FileCountLines($original_file)
For $i = 1 To $count_line
    $text = FileReadLine($original_file, $i)
    If $text <> "" Then FileWriteLine($new_file, $text)
Next

 

Link to comment
Share on other sites

Thanks for the suggestions. I realized while using the second solution that I can just remove the <br /> in the html as its html signature and this will remove the lines.

_ReplaceStringInFile($filename1,"mobile2mobile2mobile2<br />", "")

For text signature i can use the code:

$original_file = $filename1
$new_file = $sigpath & "\" & $sightm
$count_line = _FileCountLines($original_file)
For $i = 1 To $count_line
    $text = FileReadLine($original_file, $i)
    If $text <> "" Then FileWriteLine($new_file, $text)
Next

Unfortunately for the rtf signature there is no solution but no one uses rtf so they will have to put up with blank lines on that one or purchase some signature software.

 

Thanks again for your help.

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...