[+]
[+]
[+]
[-]
  
  
 [+]
 [+]
 [+]
  
  
  
 [+]
 [+]
 [-]
   
   
   
   
   
   
   
   
   
 [+]
 [+]
 [+]
 [+]
  
 [+]
  
Updated on 5/22/2019
Workflow Documentation
Scheduled Task Script Example
Direct link to topic in this publication:

PREVIOUS  |  NEXT

Scheduled Task Script Example

Quick Links


A Scheduled Task script enables you to perform operations such as assign a case, change the case status, and update custom fields.  

After your create the script, you must add it to a Scheduled Task, where you define how often the script will execute. For more information about scheduled tasks, see Scheduled Tasks


Create Scheduled Task Script

[Back to top]

In this example, we want to find all cases in the Ticketing workflow so we can perform an audit on them. We then want to move those cases to the Audit Candidate status while they await processing. To achieve this, we create a Scheduled Task script that finds all cases of the Ticketing case type, then moves them to the new status.

To create this script, you will need the following parameters, according to your specific workflow and status. For this example, we use: 

  • Workflow Unique Key: ticketing
  • Status System ID: audit_candidate

To create the script:

  1. Go to Setup > Development > Scripts.
  2. Select Script from the New menu, or click the Create New link in the instructional text.
  3. Name the script Scheduled Task - Change Status.
  4. Select the Scheduled Task script type.
  5. Enter the following code:

    // get all cases with case type Ticketing
    def caseList = resp.cases.find (""" eq 'caseType', 'ticketing' \n """); 
    
    // move all cases to Audit Candidate status
    def status = resp.getStatus('audit_candidate');
    for (def caze:caseList) {
         caze.setStatus(status);
         resp.update(caze);
    }

  6. Click Save and Publish to save the script and make it available for use.

Add Script to a Scheduled Task

[Back to top]

To add the script to a Scheduled Task:

  1. Go to Setup > Automation > Scheduled Tasks.
  2. Click the Add New link. 
  3. Provide the name for the task.
  4. In the Script field, select the Scheduled Task - Change Status script created above.
  5. Click Next.
  6. Select the recurrence schedule and start and stop dates. For more information, see Create New Scheduled Task.  
  7. Select Save.

To run the task immediately, click the   button and select Run.



Related Articles