· Mar 22 3m read

Tasks & Tricks: The Dev's Fish & Chips


Hi Community!


Do you usually work with automated tasks? Then let me share with you a pair of tips ;-)


Tip 1: How to know when my automated task will end (approximately)


Do you have an automated task that is running but you are not sure when it will end and you are at the crossroad of take the decision to stop it or wait and you are not sure if could be better wait for 5 o 10 minutes?

Here you are a tip to check when your task will finish (approximately).


For this example I have created a task with this code:


Now suppose you enter on the automated task sections and you have checked that the task have start time but the end date time is empty (so it's running) and you want to know what is doing just now the task, good, here is my first tip:

Copy your task id



Now go to the Lock Management section: System -> Manage Locks, and look up for the lock of your task id:




Click on the process Id and then in Variables:


You will be able to see the variables loaded in memory:

In my case I can see that the value of I = 9, I can refresh the screen in order to measure how many time has passed between values:


Now with this information you can make a decision with a bit more of info 😉



Tip 2 : How to follow the breadcrumb trail of a mistake:



Imagine this situation, you have an automated task that is executed every day and (for example) sends a message when one customer has an upcoming appointment.

This is the (silly) example data:



And this is the (really silly) code of your automated task:

ROUTINE Test.ExampleRoutine [Type=INT]
TestExampleRoutine ;
    For i=1:1:100
        Do ProcesCustomer(i)


    New phone, appointmentDate, result
    New today, limitDays

    Set limitDays = 3
    Set today =$H
    Set phone = $$GetCustomerPhone(id)
    Set appointmentDate = $$GetNextAppointment(id)
    If (appointmentDate - today) < (3)
        Set result = $$SendMessage(appointmentDate, phone)

    New phone,notified

    Set phone=$G(^Customers(id,"phone"))
    Set notified=$$CheckNotified(id)

    Quit phone


    New appointmentDate 

    Set appointmentDate=$G(^Customers(id,"appointmentDate"))

    Quit appointmentDate


    Set phone = ""
    Quit 0
SendMessage(date, phone)

    U 0 W "Message sended to "_phone,!

    Quit 1


(Yes I know old school code)

And this is the result of the execution from a Terminal:


(It continues until the 555000100)


Now, imagine that this is your task:

As you know, you can see all the executions of your task in the Portal in the History button.


At this moment, you are so proud of your task, but someday you decided to improve it adding a code to try to not to send messages if you launch the task twice in a day, and you decide add this method.


Then you go home really happy with your work (Probably is Friday afternoon)  an next day people start calling you because they haven't been notified of their next appointments.

Then you open the task history an see this:

But what happened!, your task worked perfectly last day. Here is where the Application Log Explorer comes in your help 💪.


Navigate to: System -> Systems Logs -> Application Errors 


Enter in the namespace where the error occurred, and select the date:




And here is your error, click on Details:


Now if you pay attention to the "SIGN ON" section you can see some variables that could give you a clue of what register has failed:


In my case you can see that when the error happened the value of "i" was 15, so I could replay the code with this exact value and found what happened. In my case was this, I've overwrited a global variable.


And those are my two task tips. I hope you could found them useful. 


Thank you very much for reading my article! 😍

Discussion (4)2
Log in or sign up to continue