JS
JS
//Archer Stuff
/*********************************************************** */
//DataFeed Parameters
var params = (typeof context !== "undefined") ? context.CustomParameters : {
BaseURI: "https://archerdev.intranet.commerzbank.com/",
Instance: "Entwicklung",
User: "A2A_Delete_SCC_Records",
Password: "***"
};
//DataFeed Token
var tokens = (typeof context !== "undefined") ? context.Tokens : {
LastRunDate: '2018-06-19T05:52:08Z',
PreviousRunContext: "XYZ"
}
function callback_archer(myJSON) {
//FINALIZE THE DATA SETS
//--As a String
myDataString = jsonToXml(myJSON).toString();
//--As a Byte Array
myDataByteArray = new Buffer(myDataString);
//XML Functions
/*********************************************************** */
function jsonToXml(jsonData) {
var bldrOpts = {
headless: true,
rootName: "ROOT",
renderOpts: {
'pretty': true,
'indent': ' ',
'newline': '\r\n',
'cdata': true
}
}
var responseBuilder = new parser.Builder(bldrOpts);
myResponse = responseBuilder.buildObject(jsonData).toString();
//Fix Timezone
myResponse = myResponse.replace(new RegExp("<state_time>.*?<\/state_time>",
'g'), fixTimeZone);
return myResponse;
}
function removeSpaces(source) {
return source.replace(new RegExp(" ", 'g'), "_");
}
function removeDashes(source) {
return source.replace(new RegExp("-", 'g'), "_");
}
function fixLeadingDigits(source) {
//End Tag
if(source.charAt(1) == '/' && ['0', '1', '2', '3', '4', '5', '6', '7', '8',
'9'].indexOf(source.charAt(2)) != -1) {
return '</_' + source.substring(2);
}
//Start Tag
if(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].indexOf(source.charAt(1))
!= -1) {
return '<_' + source.substring(1);
}
return source;
}
function fixTimeZone(source) {
//create a Date object from source data and return an ISO String
myDateString = source.substring(source.indexOf(">")+1, source.indexOf("</"));
isoString = new Date(myDateString).toISOString();
tagName = source.substring(source.indexOf("<") + 1, source.indexOf(">"));
return "<" + tagName + ">" + isoString + "</" + tagName + ">";
}
function escapeXml(unsafe) {
return unsafe.replace(/[<>&'"]/g, function (c) {
switch (c) {
case '<': return '<';
case '>': return '>';
case '&': return '&';
case '\'': return ''';
case '"': return '"';
}
});
}
/*********************************************************** */
//Global Variables
var script_start_timestamp = new Date();
var archerSessionToken = "";
//Requests
var request_1_login = {
method: "POST",
url: params.BaseURI + "/ws/general.asmx",
rejectUnauthorized: false,
headers: {
SOAPAction: "http://archer-
tech.com/webservices/CreateUserSessionFromInstance",
'Content-Type': "text/xml; charset=utf-8"
},
body: '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<CreateUserSessionFromInstance xmlns="http://archer-
tech.com/webservices/">' +
'<userName>' + escapeXml(params.User) + '</userName>' +
'<instanceName>' + escapeXml(params.Instance) +
'</instanceName>' +
'<password>' + escapeXml(params.Password) + '</password>' +
'</CreateUserSessionFromInstance>' +
'</soap:Body>' +
'</soap:Envelope>'
}
//Step 1: xyz
httpRequest(request_1_login, function handleResponse(error1, response1, body1) {
if (typeof response1 !== "undefined" && response1.statusCode == 200) {
myParser1 = new parser.Parser({explicitArray : false});
myParser1.parseString(body1, function(err, result) {
archerSessionToken = result['soap:Envelope']
['soap:Body'].CreateUserSessionFromInstanceResponse.CreateUserSessionFromInstanceRe
sult;
//console.log("archerSessionToken: "+archerSessionToken);
callback_archer({ergebnis:'Login erfolgt', token: archerSessionToken});
});
}
else {
throw new Error("The request did not return a 200 (OK) status.\r\nThe
returned error was:\r\n" + error1 + response1 + body1);
}
});