Migrate Asset History from OP to OD as an Attachment.

Migrate Asset History from OP to OD as an Attachment.

Currently, there is no option to transfer asset history from the OP instance to the OD instance. As a workaround, a Python script retrieves history data, generates a readable PDF file, and uploads it as an attachment to the corresponding asset in the OP instance. This attachment is then migrated along with the asset during the OP to OD migration.

The script requires specific configurations in config.json. In PostgreSQL, the database port,user and password must be set. Asset history data is fetched from the CIHistory table, while resource state and ownership history are retrieved from ResourceStateHistory and ResourceOwnerHistory. The CIHistory data is generated as a separate PDF, and ownership history is also stored in a separate PDF. Additionally, an authentication token and  URL of to access applicatoin must be configured in config.json to invoke the asset API and upload the attachments.


Info
Required Packages to run the script:
Notes
psycopg2: For connecting to and interacting with a PostgreSQL database.
weasyprint: For generating PDF files from HTML content.
requests: For making HTTP API requests.

Command to Install the Packages :
Windows:
pip install psycopg2 weasyprint requests

Linux:
pip install psycopg2-binary weasyprint requests
sudo apt update
sudo apt install -y libpango-1.0-0 libpangoft2-1.0-0 libpangocairo-1.0-0 libcairo2

Sample History PDF will be attached for referrence.

                  New to ADSelfService Plus?

                    • Related Articles

                    • Asset Ownership History Report

                      Please use the below query to get the report on Asset Ownership History. SELECT r.resourcename AS "Workstation Name", ct.componenttypename AS "Product type", rs.displaystate AS "Asset State", aa.first_name AS "Assigned User", LONGTODATE(sh.starttime) ...
                    • Query to show Asset state history ( MSSQL)

                      Tested in MSSQL build (14306) SELECT res.resourcename 'Asset Name', res.assettag 'Asset Tag',res.serialno 'Asset Serial No.', rs2.statedesc 'Previous State',rs1.statedesc 'Current State',DATEADD(s,DATEDIFF(s,GETUTCDATE() ,getdate()) + ...
                    • Add Attachment API assistance for other tools

                      Our sample html to test Add Attachment API works well. However many customers are having trouble converting it to code/other tools (Powershell, python, Postman, Curl). Hence we are posting this article to get it using Postman for other tools. We can ...
                    • Adding attachment to Resolution using API

                      PURPOSE: To add an attachment to the resolution via API. STEPS: 1) Upload the attachment file and obtain the attachment ID: URL: <domain_url>/api/v3/requests/upload Method: POST Payload: files ( input_data = <file_content> ) Response: 2) Add the ...
                    • Query for request attachment details (MSSQL & PGSQL)

                      Tested in builds from PGSQL (14300) or MSSQL (14306) Requests with Attachment, its name and path SELECT ad.ORG_NAME AS "Account", wo.WORKORDERID AS "Request ID", wo.TITLE AS "Subject", ti.FIRST_NAME AS "Technician", sa.ATTACHMENTNAME "Attachment ...