Extender and Process Scheduler

Logging Script Results - Tips to Write Extender Scripts for Process Scheduler

Extender includes a LOG function. Process Scheduler can use the output from the LOG function to flag the step as "Success" or "Failure".

If the script returns "OK", Process Scheduler thinks it is a success, anything else is an error.

 

Refer to the Example Extender Script.py file in the VIXXA folder where Sage 300 is installed for details.

Copy
Logging script example
# example 1 - log text only
def main(args):
    log("OK|0|This is the log message '" + args + "'")

# example 2
def main(args):
    status, errCnt, logmsg = ExtenderScriptFunction(args)
    t = status + "|" + str(errCnt) + "|" + logmsg
    #showMessageBox("Write back to OZ: " + t)
    log(t)

 

You can save the log in a text file (in the Sage 300 Shared data folder for example).

Set "logmsg" to the full path of the log file and you will be able to open the last log file from the Process Scheduler window.

This is particularly useful if the log is too long and is truncated when viewed in the Process Scheduler screen.

Write your log to a file, e.g. c:\shareddata\mylog.txt, then:

You can use the $ATTACHLOG variable in the Process Scheduler email template to email the log file from Process Scheduler.

Copy

Log to File examples

# example 1 - log to a text file
def main(args):
    log("OK|0|c:\\shareddata\\mylog.txt")    

# example 2 - log only if script is called by Process Scheduler
def ImportInvoices():

    # clear the file and write in a start message:
    msg = "commence logging..."
    fnCaller = ""
    logToFile(msg, fnCaller)
    # add code to function
    
    # return log to PS
    logmsg = getOrgPath() + "\\" + user + "_" + OZLogFile + "_" + today() + ".txt"
    if failCnt > 0:
        return "Error", failCnt, logmsg
    else:
        return "OK", 0, logmsg

def logToFile(msg, fnCaller = ""):
    global companyDir
    
    if companyDir == "":
        companyDir = getOrgPath()
        
    fileFullName = companyDir + "\\" + user + "_" + sLogFile + "_" + datetime.datetime.now().strftime("%Y%m%d") + ".txt"
    f = open(fileFullName, "a")
    
    # Write out the log message.
    logMsg = "[{}]_[{}]\n\t {}\n".format(fnCaller, datetime.datetime.now().strftime("%H:%M:%S"), msg)
    f.write(logMsg)
    f.close()

def main(args):
    status, errCnt, logmsg = ImportInvoices()    
    t = status + "|" + str(errCnt) + "|" + logmsg
    if program == "AS1001":
        # assume it is being called by Process Scheduler:
        log(t)