Applies To:
GroupID 8 and above – Synchronize
Business Requirement:
In GroupID, different kinds of files, such as CSV and .txt, are used to update attributes in Active Directory through a Synchronize job.
We have a requirement that when a CSV file is processed by a Synchronize job, it should be moved to the archive folder present on our server and renamed by appending the date-stamp to the file name. For example, if the file name is Excel123HR12, it should be moved to the archive folder with the name Excel123HR12-datemonthyear.
Is it possible with GroupID Synchronize?
Solution:
Yes, it is possible with a GroupID Synchronize job. Use the Global Script Editor feature for the Synchronize job to achieve it.
Steps:
-
Launch GroupID Management Console.
-
Click Synchronize > All Jobs and then click the required Synchronize job.
-
On the Select Source page, make sure that relevant information is updated. In this example, we have taken a file, Excel123HR12.csv, from the root drive, C:\.
-
On the Field Map(s) page, click Edit Global Script.
-
The Global Script Editor is displayed.
-
Locate the following lines of code:
Sub DTM_Shutdown(ByVal dtmsource As Object, ByVal args As EventArgs) Handles DTM.Shutdown
' User-definable script goes here -----------------
' -------------------------------------------------
End Sub -
Replace the above lines of code with the following by changing parameters as required. The parameters are:
-
Dim SourcePath As String="C:\Excel123HR12.csv"
In the code below, change the path of the file to the source file.
In this example, it was placed in the root drive, i.e., C:\ and it was named as Excel123HR12.csv. -
Dim DestPath As String="C:\Archive\Excel123HR12.csv"
In the code below, change the path of the file to the folder where you want to archive this CSV file.
In this example, we transferred the file to the Archive folder in the C drive, C:\Archive\Excel123HR12.csv.
Make sure that the Archive folder or any other folder you want to transfer the CSV file already exists.
Sub DTM_Shutdown(ByVal dtmsource As Object, ByVal args As EventArgs) Handles DTM.Shutdown
' User-definable script goes here -----------------
' User-definable script goes here -----------------
Dim SourcePath As String="C:\Excel123HR12.csv"
Dim DestPath As String="C:\Archive\Excel123HR12.csv"
Dim FileName As String="Excel123HR12"
If System.IO.File.Exists(SourcePath) Then
File.Move(SourcePath,DestPath)
Dim DT as Date=Date.Now
Dim NewName As String = FileName & "-" & DT.Day & DT.Month & DT.Year & ".csv"
'msgbox(NewName)
My.Computer.FileSystem.RenameFile(DestPath, NewName)
Else
'msgbox("FileNotPresent")
End if
' -------------------------------------------------
End Sub -
-
After that, click Build > Compile Script.
-
Close the Global Script Editor and save the changes by clicking Yes.
Note: | After the job is run, the file will be sent to the Archive folder specified in the destination path. So, if you try to run the job again, it will not run as the file would not be available at the Source path. To rerun the job, provide the file back in the original path, or change the path in the Global Script Editor. |