Procedure transfer from an Excel file to Service Desk plus using JScript ans IE's ActiveX.
It is a script i have done at work to do things faster. I mainly keep it for reference purposes
because of course i do not have service desk plus at home :)
Files overview --------------------------------------------
proc-xfer.wsf Script descriptor
clipboard.js Copy-to-clipboard routine
serviceDesk.js Wrapper for ServiceDesk GUI
proc-xfer.js Main()
ie_test.js Tests for the wrapper
dump.js Dump excel file
pad.js Formatting routine
checkfiles.js Check files consistency
alreadydone.js Dump already-done files
__________________________________________________________________________________________
file: proc-xfer.wsf
file: topics.js
var topics = Array();
topics["Citrix"] = "2407";
topics["AntiVirus"] = "2408";
topics["Internet"] = "7";
topics["Office Tools"] = "602";
topics["Fax-Copier"] = "2";
topics["GroupWise"] = "306";
topics["Laptop"] = "1805";
topics["PRINTER"] = "3";
topics["Licenses"] = "602";
topics["Acrobat"] = "602";
topics["Network"] = "6";
topics["GPII"] = "602";
topics["Security Systems"] = "2409";
topics["NT Workstation"] = "1802";
topics["Dell System"] = "1802";
topics["Pass2"] = "903";
topics["Web"] = "7";
topics["PC Class"] = "1807";
topics["FTP Server"] = "6";
topics["Phones"] = "2406";
topics["Email System"] = "305";
topics["Swift"] = "1811";
topics["intranet"] = "6";
__________________________________________________________________________________________
file: clipboard.js
var ieclipboard = new ActiveXObject("internetexplorer.application");
ieclipboard.Visible = true;
function htmlentities(s) {
var string = new String(s);
string = string.replace(/\//g, "%2F");
string = string.replace(/\?/g, "%3F");
string = string.replace(/=/g, "%3D");
string = string.replace(/&/g, "%26");
string = string.replace(/@/g, "%40");
string = string.replace(/\\/g, "%5C%5C");
return string;
}
function setClipboardContents(string)
{
ieclipboard.Navigate("javascript:clipboardData.setData('Text','"+htmlentities(string)+"')");
WScript.Sleep(200);
}
//setClipboardContents("clipboard");
__________________________________________________________________________________________
file: serviceDesk.js
function raiseWindow(ie) {
ie.visible = false;
ie.visible = true;
}
function openServiceDesk() {
var ie = new ActiveXObject("internetexplorer.application");
ie.Visible = true;
ie.Navigate("http://1.1.1.148:8080/HomePage.do");
while(ie.Busy)
WScript.Sleep(200);
ie.document.all.username.value = "rdupuis";
ie.document.all.password.value = "welcome";
ie.document.login.submit();
while(ie.Busy)
WScript.Sleep(200);
return ie;
}
function goNewSolution(ie) {
ie.Navigate("http://1.1.1.148:8080/AddSolution.do?tID=305");
while(ie.Busy)
WScript.Sleep(200);
WScript.Sleep(200);
}
function setSolutionTitle(ie, title) {
ie.document.addSolutionForm.title.value = title;
}
function setSolutionTopicID(ie, id) {
ie.document.addSolutionForm.topicID.value = topic;
}
function setSolutionKeywords(ie, keywords) {
ie.document.addSolutionForm.keywords.value = keywords;
}
function addAttachment(ie, filename) {
ie.Navigate("javascript:invokeFileAttachment('Solutions')");
while(ie.Busy)
WScript.Sleep(200);
WScript.Sleep(500);
setClipboardContents(filename);
raiseWindow(ie);
ie.document.getElementById('AttachBtn').focus();
var sh = new ActiveXObject("WScript.Shell");
sh.SendKeys("^v");
WScript.Sleep(500);
ie.document.UploadAttachment.submit();
while(1)
{
WScript.Sleep(500);
try{
ie.document.getElementById('AttachBtn').focus();
} catch(e){
break;
}
}
WScript.Sleep(500);
}
function submitSolution(ie) {
ie.document.addSolutionForm.addKBButton.click();
while(ie.Busy)
WScript.Sleep(200);
WScript.Sleep(500);
}
__________________________________________________________________________________________
file: proc-xfer.js
function pad(size, strobj)
{
var str = new String(strobj);
var npad = size - str.length;
for(var i=0; i