Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Script to move a source fine and rename after integration

(0) ShareShare
ReportReport
Posted on by

Should be fairly straight forward, but I'm looking for a piece of vb script to put in the after integration event to move the source file and rename with the current date/time, only if the integration was a success. IM version 12.00.1753

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Script to move a source fine and rename after integration

    Hello - I found that the script in Integration Manager is missing a Quote after Orders (in other words you need a quote after the file name you are using. )

     

      sDestinationFile = "C:\Integrate\Done\Orders & Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & ".txt"

  • Suggested answer
    L Vail Profile Picture
    65,271 on at
    RE: Script to move a source fine and rename after integration

    Here's the last one I've got, it sends an Outlook E-mail Containing a Post-Integration Text Log

    This one is an After Integration script and is probably closest the success script you were wanting.

    '****************GET THE LOG FILE INFO******'*******************************************

    'Set the path to the log files. Edit this line as appropriate

     sLogPath="C:\IM\Logs\"

     Set pFSO =  CreateObject("Scripting.FileSystemObject")

     Set pFolder = pFSO.GetFolder(sLogPath)

     dtDateCreated=CDate("1/1/1900")

     For Each File In pFolder.Files  

       If File.DateCreated > dtDateCreated then

       dtDateCreated = File.DateCreated

       sFileName=File.Name

       End If

     Next

    '*******************************************

    '************CREATE AND SEND THE E-MAIL*****

    '*******************************************

    'Edit the following line to indicate the e-mail address to  

    'which notification should be sent

     sAddress = "adminstrator@mycompany.com"

    'Set the subject line for the e-mail:

     sSubject = "Integration Log"

    'Generate the body of the e-mail

    'Edit the following text as appropriate

     sBody = "Log file attached for integration: Customers"

    sBody = sBody & vbCrLf & vbCrLf

     sBody = sBody & vbCrLf & "Date of Integration: " & Date()

     sBody = sBody & vbCrLf & "Time of Integration: " & Time()

    'Create an instance of Outlook & create an e-mail item

     Set pOutlook=CreateObject("Outlook.Application")

     Set pMAPI = pOutlook.GetNamespace("MAPI")

     Set pMail = pOutlook.CreateItem(0)

    'Set the recipient, subject & body of the e-mail

     pMail.Recipients.Add(sAddress)

     pMail.Subject = sSubject

     pMail.Body = sBody

    'Add an attachment

     Set pAttachments = pMail.Attachments

     pAttachments.Add sLogPath & sFileName

    'Send the e-mail

     pMail.Send

    'Clean up

     Set pMail = Nothing

     Set pMAPI = Nothing

     Set pOutlook = Nothing

    Kind regards,

    Leslie

  • Suggested answer
    L Vail Profile Picture
    65,271 on at
    RE: Script to move a source fine and rename after integration

    This one, also from the script library, sends an Outlook email that notifies the recipient of Document Errors. It is considered a Document Error script.

    'Edit the following line to indicate the e-mail address to  

    'which notification should be sent

     sAddress = "administrator@twoinc.com"

    'Set the subject line for the e-mail:

     sSubject = "Integration Manager Document Error"

    'Generate the body of the e-mail

    'Edit the following text as appropriate

     sBody = "Error in integration: Customers" & vbCrLf & vbCrLf

     sBody = sBody & "Document Number: " & DocumentNo & vbCrLf

     sBody = sBody & "Customer ID = " & SourceFields("Customer ID")

     sBody = sBody & vbCrLf & "Date of Integration: " & Date()

     sBody = sBody & vbCrLf & "Time Error Occurred: " & Time()

    'Create an instance of Outlook " create an e-mail item

    Set pOutlook= CreateObject("Outlook.Application")

     Set pMAPI = pOutlook.GetNamespace("MAPI")

     Set pMail = pOutlook.CreateItem(0)

    'Set the recipient, subject " body of the e-mail

     pMail.Recipients.Add(sAddress)

     pMail.Subject = sSubject

     pMail.Body = sBody

    'Send the e-mail

     pMail.Send

    'Clean up

     Set pMail = Nothing

     Set pMAPI = Nothing

     Set pOutlook = Nothing

    Kind regards,

    Leslie

  • Community Member Profile Picture
    on at
    RE: Script to move a source fine and rename after integration

    thanks that should do it.

  • Verified answer
    L Vail Profile Picture
    65,271 on at
    RE: Script to move a source fine and rename after integration

    This is from the script Library. It's a script that renames the source file after integration

    It is placed as an After Query script:

    'Set the Path & Filename of the Source file and the Destination

    'file. In this example, the destination file is named "Done 20000829",

    'where "20000829" represents the system date, in the following

    'format:  yyyymmdd.

    sSourceFile = "C:\Integrate\Orders.txt"

    sDestinationFile = "C:\Integrate\Done\Orders" & Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & ".txt"

    'Create a File System Object

     Dim pFSO

     Set pFSO = CreateObject("Scripting.FileSystemObject")

    'Copy and rename the file

    'The "True" parameter indicates that if the file already exists

    'in the destination, then it will be overwritten

     Call pFSO.CopyFile(sSourceFile, sDestinationFile, True)

    Stay Tuned for the next one.

    Kind regards,

    Leslie

    I edited this post to include the missing quotes (in red above) thanks to 'Crystal Clear 1313'

    LV

  • Community Member Profile Picture
    on at
    RE: Script to move a source fine and rename after integration

    To elaborate, regardless of how we define success, this would then run. I'm not familiar with the scripting, but I'd assume there is some switch one can evaluate for success. If that is true, then move the file. I can always move it back, rename, and rerun if there was some sort of issue.

  • Community Member Profile Picture
    on at
    RE: Script to move a source fine and rename after integration

    Yes it would.

  • L Vail Profile Picture
    65,271 on at
    RE: Script to move a source fine and rename after integration

    Hi,

    Define success. If you have a max of 10 errors allowed and received 6 the integration will complete. Would this be a success?

    Moving the file and renaming it is no problem, I think there is a script already written in the Script Library, but we need to know what you consider a success.

    Kind regards,

    Leslie

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
Almas Mahfooz Profile Picture

Almas Mahfooz 3 User Group Leader

Featured topics

Product updates

Dynamics 365 release plans