Lenovo warranty info in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 05:29 AM
Hi,
Does anyone already implemented a way of working to obtain from Lenovo the Asset warranty end dates and make these dates available on the Lenovo Assets in ServiceNow?
I am thinking of a scheduled batch process to collect and update this info on a weekly basis. This info will be used for example in Asset Repair assessments and Hardware Asset Refresh Order process to trigger certain Assets for refresh.
Looking forward to your suggestions,
Ed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 01:08 PM
Haha I had a similar requirement to query the hardware asset table for CIs in allocated state collect their serial numbers, then query the Lenovo site and retrieve their end dates and update them in ServiceNow, then to show the updated CIs in an Excel file which gets attached to an email notification.
You will need to be provided with an end point to which you will connect on Lenovo, and a clientID.
With this you will create a REST message, and call that REST message from a scheduled job after youre doing querying for the serial numbers of the assets you want to get end dates.
Script from script include called in the scheduled job
var GetAssetWarranties = Class.create();
GetAssetWarranties.prototype = {
initialize: function() {
},
Warranty: function(){
/* WARNING:
* We had some issues with the lenovo api returning the wrong product data.
*
* Sent to api: 21312
* API Responds with: PC1C7QEP */
/* global variables */
var serials = [];
var api_response = [];
var invalid_Serials = [];
/* query alm hardware table */
var alm_hardware = new GlideRecord("alm_hardware");
alm_hardware.addQuery("ci.manufacturer", "f645151ddbec809079ec304d3b9619c8"); //This sys_id in our instance was from Lenovo manufacturer/company
alm_hardware.query();
while (alm_hardware.next()) {
serials.push(alm_hardware.serial_number.toString());
}
/* send api request and collect response */
try {
var message = new sn_ws.RESTMessageV2("Test - lenovo", "Default GET");
for (var i = 0; i < serials.length; ++i) {
message.setQueryParameter("serial", serials[i]);
var response = message.execute();
var response_body = response.getBody();
var response_status = response.getStatusCode();
switch (response_status) {
case 200: break;
case 201: break;
case 202: break;
default:
//gs.eventQueue("eventName",current,current.number,gs.getUserName());
}
api_response.push(JSON.parse(response_body));
}
} catch (exception) {
/* handle api connection error */
//gs.eventQueue("eventName.failed",current,current.number,gs.getUserName());
}
/* update database records */
for (i = 0; i < api_response.length; ++i) {
/* handle api error */
if (api_response[i].ErrorCode !== undefined) {
invalid_Serials.push(api_response[i].Serial.toString());
// gs.log("[ERROR] Lenovo API - Serial: " + api_response[i].Serial + " ErrorCode: " + api_response[i].ErrorCode + " ErrorMessage: " + api_response[i].ErrorMessage, "lenovo.api");
// continue;
}
//I dont remember why this GDT object needed to be initialized but I just remember it didnt work right without it
var expiration_date = new GlideDateTime("1999-01-01 00:00:00");
/* find latest expiration date */
for (var j = 0; j < api_response[i].Warranty.length; ++j) {
var end_date = new GlideDateTime(api_response[i].Warranty[j].End);
if (expiration_date.before(end_date)) {
expiration_date = end_date;
}
}
alm_hardware = new GlideRecord("alm_hardware");
alm_hardware.addQuery("serial_number", api_response[i].Serial);
alm_hardware.query();
while (alm_hardware.next()) {
alm_hardware.setValue("warranty_expiration", expiration_date.getDate());
alm_hardware.update();
gs.print(expiration_date.getDate());
}
}
gs.log(invalid_Serials, "SERIAL-NUMBERS");
var string_Serials = invalid_Serials.toString();
gs.eventQueue("eventName.invalid.serial", current, string_Serials, gs.getUserName());
//This part was for generating a CSV file with the updated assets so feel free to remove it if you dont need it
var today = new Date().toISOString().slice(0, 10);
var splited = string_Serials.replace(/,/g, "\n");
var csvHeaderRow = "Serial Number";
var valueRow = splited;
var file_name = "SerialNumber " + today + ".csv";
var content_type = "text/csv";
var rec_sysid_arr = [];
//Custom table needed for the CSV attachments again this whole bottom part feel free to remove if you dont need to generate a CSV
var rec = new GlideRecord("u_manufacturer_attachment");
rec.initialize();
rec.setValue("u_file_name" , file_name);
var new_rec = rec.insert();
rec.get(new_rec);
var sa = new GlideSysAttachment();
var document = csvHeaderRow + "\n" + valueRow;
var atch_id = sa.write(rec, file_name , content_type, document);
},
type: 'GetAssetWarranties'
};
Read through the script comments carefully and adjust accordingly. Also note that if they changed the response structure this might not work so further adjustment might be needed as this was done I think 2.5 years ago.
Please mark helpful/resolved if it indeed was it would mean a lot 😄
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 12:25 AM
Many thanks Harun,
I will hand-over this info towards one of my technical guys. Reading this I think it will help us.
Cheers,
Ed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 08:53 AM
Ran through this and does it update the ALM-Hardware Warranty_expire column? Need some assistance if available to determine that this worked.
Jason