---
sourceDocument: Xanadu Strategic Portfolio Management
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/it-business-management

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu Strategic Portfolio Management

ft:clusterId :

    - itbm

bundleId :

    - itbm

workflow :

    - Technology


---

# Add diagnostic and fix scripts

# Add diagnostic and fix scripts {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

Add diagnostic scripts to scan the data in your application for any corruption. You
can also attach fix scripts to rectify the corrupt or invalid data identified by the
diagnostic script.

## Before you begin

Role required: adt_admin

## About this task

The results of the filter conditions that you specify in a [diagnostic feature](https://servicenow-prod.fluidtopics.net/8ni53d21BnILrXzAkUqi0A "Create and add diagnostic features, which consist of single or multiple diagnostic scans that execute mapped scripts to detect data corruption or invalid data.") are used as an
input for the diagnostic script while executing. You can also use the result of one
script in subsequent scripts.

## Procedure

1. Navigate to AllApplication Diagnostics ToolScripts.
2. Click New.
3. On the form, fill in the fields.  
   {#add-diagnostic-and-fix-script__table_ymh_4kr_wjb__entry__2}

   | Field | Description |
   |-|-|
   | Name | Name of the diagnostic script. Use a name that clearly explains the objective of the script. The script name also enables you to identify the correct script while mapping the script to a feature when creating a diagnostic scan. |
   | Description | Details describing the actions of the diagnostic script. |
   | Diagnostic script | The code for the diagnostic script. The following example shows a diagnostic script to identify tasks with an invalid top portfolio. /* - Inputs can be accessed from scanContext.input as per, the key specified in feature input table. eg.  scanContext.input.projectSysID - To pass variables from the one script to another script use varSpace in scanContext. eg.  scanContext.varSpace.variable1 = '...'; */ (function(scanContext) { try { var errorTasks = []; var encodedQuery = scanContext.input.projectFilter; var now_GR = new GlideRecord("pm_project"); gr.addEncodedQuery(encodedQuery); gr.query(); while (gr.next()) { var entitySysID = gr.getValue("sys_id"); var projectData = new ProjectData(entitySysID); var projectTopTaskValidator = new ProjectTopTaskValidator(projectData); if (projectTopTaskValidator.tasksWithInvalidTopPortfolioPresent()) { var failedTasks = projectTopTaskValidator.getTasksWithInvalidTopPortfolio(); if (failedTasks && failedTasks.length) { for (var i = 0; i < failedTasks.length; i++) { errorTasks.push(failedTasks[i].sys_id); } } } |
   [Table 1. Diagnostic Scripts form]

   {#add-diagnostic-and-fix-script__table_ymh_4kr_wjb}
4. **Optional:** Include a script for fixing the corrupt or invalid data identified by the diagnostic script.
   1. Select the Has Fix script check box.
   2. Click the Edit User Roles icon (![Edit User Roles icon]()) and choose the roles that can access the diagnostic script.
   3. In the Fix script section, add the code for the fix script.
   {#add-diagnostic-and-fix-script__substeps_ykk_llc_mkb}
5. Click Submit.
{#add-diagnostic-and-fix-script__steps_tbd_zym_xjb}

*[\>]: and then


