How to debug a python/deluge script

How to debug a python/deluge script

Common Debugging steps:
1.  Confirm if all the API used are in proper format:
  • In latest v3 APIs, "format": "json" is removed from parameters
  • Notes addition API is modified from:   "request_notes" to "notes" in recent builds
2.  Check if the udf_fields used within the script are present in the request template.
3.  Check if the technician key/integration key used is valid and has proper roles for doing the API operation
4.  For child request creation: 
  • Check if the childjson defined is valid.  Use any json parse or online site to verify the childjson content.
  • Check if the parent request template is properly defined.
5.  Validate the query output for Custom Schedule operations.  Also, check if all the columns used in the script are present in the query output. (Note:  python is case sensitive, so please maintain the same case when using the query output in the script.)
6.  Request Update:
  • Before updating any request field, make sure that all mandatory fields are filled out.
  • Add request_status_comments field for status update operations
  • When closing a request, all of the request closing rules must be fulfilled.
  • To verify if the input data used is correct, we can invoke the API with the same input content from doctool.
  • Check if the API names for the additional field are used correctly
  • Duplicate Request:
    • Check if proper field is sent to "getDynamicFieldValue" function

    • eg: like $requester,$name in case of getting requester name
7.  Use proper returnjson format to print the script output. {"result":"<success/failure>","message":"<Message Content>"}
8.  URL errors:
  • In most of the cases URL is reachable from client machines but not from server
  • So, check if the URL used in the API invocation is reachable from the server where SDP is installed..
9.  Check if the configuration.json or the global_function is correctly defined.
10.  Check if proper headers are added.  For Task module we need to add  " 'accept':'vnd.manageengine.v3+json' " in the header to use the latest v3 task API.  Without this header, it will invoke the old task API.
11.  For CAB addition:
  • Ensure that the users added are a member of a CAB group.
  • When using v3 API for adding CAB, make sure that the workflow is not configured for the change request.


For Python:
1.  py/python not found:
  • Confirm if python path is set in as environment variables.
  • If not, invoke the python.exe from the installation folder.  Eg: c:\\python\python39\python.exe
2.  Please check the error message, In case of "No module found" then import that module.
  • Open Command prompt,
  • Type "pip install <module_name>" Replace <module_name> with the required module names
3.  Take a copy of the request object from the API doctool and invoke the script from command prompt
  • Open Doctool, Goto view request.
  • Enter the request ID
  • Copy the response content and save the file as a requestObject.json under /sdp_home/integrations/custom_scripts folder
  • Now, we can use this json file to invoke the script from command prompt (location should be /sdp_home/integrations/custom_scripts and Example py file_name.py requestObject.json )
4.  Print the API response to see what exactly is the error.
  • All the APIs are invoked either using the functions in the functions.py file or the python request functions are used.
  • eg: Default Python functions: request.post\request.put\request.delete 
  • eg: Functions.py postURL\putURL\deleteURL
  • The response will be stored to a variable, we can print the same and debug
  • print(response.json())
5.  Indentation error:
  • It is better if the customer has the basic editors, eg: wordpad, notepad++
  • To remove indentation errors, you can copy paste the same number of spaces from the previous line with the same indentation.
6.  Make sure that the customer has updated the date properly, incase if the customer has to update the script with the additional field info or resource question info or be it simple default field values that have to be updated.
7.  SSL Error:  Make sure that verify=False, is set for all API related operations.     
8. Avoid invoking Post API with both data and params.
9. Python version should be > 3.4


For Deluge:
1. Custom Schedule :
  • Ensure if the query report name used in the script is same as the saved query report. [case sensitive]
  • Ensure if all the columns used in the script are included in the query report. [case sensitive]
  • Also note that the column name and report name are case sensitive.  
2.  We cannot do any Admin related configuration changes via deluge.
3.  Verify if all the global functions used are invoked correctly in the custom functions.

                  New to ADSelfService Plus?

                    • Related Articles

                    • How to implement dynamic request approval using FAFR and custom triggers - Deluge

                      This is a sample script written in Deluge to handle Conditional Approvals for Incident \ Service Requests, through Custom Triggers using Field and Form Rules.  One of the advantages of using this script that no modification in the script is required ...
                    • Create multiple Child Requests - Deluge Script

                      This is a sample deluge script to automatically trigger the creation of multiple child requests from a parent request, based on the request template chosen. The request ID of the child requests will be added as a Note in the parent request. This is ...
                    • Update a request based on certain values - Deluge

                      This post describes the use of a deluge script to update requests based on values given a global function, namely "request_properties".  This action can be performed using Custom Triggers. Refer to this link for Python ...
                    • Python script to automate FCR

                      Please find the attached Python script on this link  to automate FCR via custom trigger when the request is created and resolved by the same technician. The link contains two Python scripts with the name FCR.py (this script can be used when MSP is ...
                    • Python Troubleshooting steps

                      Here we are listing the troubleshooting steps for the python script to be executed 1. Check whether python is installed or not in the sever where SDP is installed 2. If it's installed check the version of python ( Preferable version should be above ...