Best JavaScript code snippet using best
TestWorker.js
Source:TestWorker.js
1//2// TestWorker.js3//4// Normally called from TestWorker.asp5//6// Global variables7// baseLegacyURL: from submitting form - will determine which legacy query to run.8// baseCoreURL: from submitting form to determine which Fusion environment9// to go to for the employee information. Initially DEV URL's for now.10// legacyqueryid: for selecting which query to run. Dependent on legacysource.11// curperson: current person (ID) that we are dealing with12// debugging: Boolean - true = write debug statements to console.log13//14var defaultlegacyqueryid = "?id=49";15// N.B. baseCoreURL may chnage aftre each major Oracle upgrade16var baseCoreURL = "https://edzz-test.hcm.em3.oraclecloud.com/hcmCoreApi/resources/11.12.1.0/";17// N.B. baseLegacyURL will chnage depending on whic legacy system is selected (paramSetup)18var baseLegacyURL = "http://its-n-jcnc-01/UoB/fetchJSON.asp";19var baselegacyqueryid = "49";20var curperson = 5500165;21var debugging = true;22var comparisonSummary = new Object();23var fusionuser = "TECHADMIN6";24var fusionpassword = "Banzai29";25// ============================================================================26function debugwrite(text) {27 if ( debugging ) {28 console.log(text);29 }30}31// ============================================================================32function paramSetup() {33 var whichlegacy;34 var whichfusion;35 var debugchoice;36 // Fetch parameters from CheckWorker.asp form37 curperson = $('#personcode').val();38 whichlegacy = $('#legacysystem').val();39 whichfusion = $('#targetsystem').val();40 debugchoice = $('#debugmode').val();41 // Establish debugging mode42 if ( debugchoice == "Y" ) {43 debugging = true;44 } else {45 debugging=false;46 }47 debugwrite("Values from CheckWorker form before any checks or defaults applied:");48 debugwrite(curperson);49 debugwrite(whichlegacy);50 debugwrite(whichfusion);51 debugwrite(debugchoice);52 debugwrite(baselegacyqueryid);53 curperson = curperson || 5500165;54 // Construct appropriate starting Fusion url55 // N.B. This URL usually changes with each major release of Fusion HCm Cloud56 baseCoreURL = "https://"+whichfusion+".hcm.em3.oraclecloud.com/hcmCoreApi/resources/11.12.1.0/";57 // Construct appropriate starting legacy URL58 // Done this way to preserve consistent use of query ID's across the legacy queries59 if ( whichlegacy == "ACCESS") {60 baselegacyqueryid = "";61 baseLegacyURL = "http://its-n-jcnc-01/UoB/fetchJSON.asp";62 }63 if ( whichlegacy == "ALTAHRN") {64 baselegacyqueryid = "49";65 baseLegacyURL = "http://its-n-jcnc-01/UoB/fetchALTA.asp?id=";66 }67 if ( whichlegacy == "WORKLINK") {68 baselegacyqueryid = "21";69 baseLegacyURL = "http://its-n-jcnc-01/UoB/fetchALTA.asp?id=";70 }71 // Adjust URLs to reflect submitted person code (in curperson)72 debugwrite("Values from CheckWorker form AFTER any checks or defaults applied:");73 debugwrite(curperson);74 debugwrite(whichlegacy);75 debugwrite(whichfusion);76 debugwrite(debugchoice);77 debugwrite(baselegacyqueryid);78}79// ============================================================================80// Needs refactoring to use getLegacyEmployee and get FusionEmployee81function generateEmployeeComparisonTable() {82 var myperson = curperson || '5500165';83 var fusionurl = baseCoreURL + "emps?onlyData&limit=10000&q=PersonNumber=";84 var legacyurl = baseLegacyURL + "?id=" + baselegacyqueryid + "&p1=";85 var thefusionemployee = {};86 var thelegacyemployee = {};87 debugwrite("Calling paramSetup");88 paramSetup();89 debugwrite("After paramSetup");90 legacyurl += myperson;91 fusionurl += myperson;92 thelegacyemployee = getLegacyEmployee(myperson);93 console.log("thelegacyemployee ");94 console.table(thelegacyemployee);95 thefusionemployee = getFusionEmployee(myperson);96 console.log("thefusionemployee ");97 console.table(thefusionemployee);98 var comparison = {};99 // Must apply developed transforms before doing Y/N comparison100 var dummy = fusionTitleCode(thelegacyemployee.TITLE);101 comparison.Title = thefusionemployee.Salutation == dummy ? "OK" : "Titles differ";102 comparison.Forename = thefusionemployee.FirstName == thelegacyemployee.FORENAME ? "OK" : "Forenames differ";103 comparison.Surname = thefusionemployee.LastName == thelegacyemployee.SURNAME ? "OK" : "Surnames differ";104 comparison.Preferredname = thefusionemployee.PreferredName == thelegacyemployee.PREFERREDNAME ? "OK" : "Preferred names differ";105 comparison.PersonCode = thefusionemployee.PersonNumber == thelegacyemployee.PERSONNUMBER ? "OK" : "Person ID's differ";106 comparison.HomeTelephone = thefusionemployee.HomeTelephone == thelegacyemployee.HOMEPHONENUMBER ? "OK" : "Home telephone numbers differ";107 comparison.WorkEmail = thefusionemployee.WorkEmail == thelegacyemployee.WORKEMAIL ? "OK" : "Titles differ";108 // Now do checks on address components109 var addressmessage = "";110 addressmessage += thefusionemployee.AddressLine1 == thelegacyemployee.ADDRESSLINE1 ? "" : " line 1 different,";111 addressmessage += thefusionemployee.AddressLine2 == thelegacyemployee.ADDRESSLINE2 ? "" : " line 2 different,";112 addressmessage += thefusionemployee.AddressLine3 == thelegacyemployee.ADDRESSLINE3 ? "" : " line 3 different,";113 addressmessage += thefusionemployee.City == thelegacyemployee.CITY ? "" : " town different,";114 addressmessage += thefusionemployee.Region == thelegacyemployee.REGION ? "" : " region different,";115 addressmessage += thefusionemployee.Country == thelegacyemployee.COUNTRY ? "" : " country different,";116 addressmessage += thefusionemployee.PostalCode == thelegacyemployee.POSTALCODE ? "" : " postcode different,";117 comparison.Address = addressmessage == "" ? "OK" : "Addresses differ:"+addressmessage;118 // End of address components checks119 comparison.DateOfBirth = thefusionemployee.DateOfBirth == thelegacyemployee.DATEOFBIRTH ? "OK" : "Dates of birth differ";120 dummy = fusionEthnicityCode(thelegacyemployee.ETHNICITY);121 comparison.Ethnicity = thefusionemployee.Ethnicity == dummy ? "OK" : "Ethnicities differ";122 comparison.Gender = thefusionemployee.Gender == thelegacyemployee.GENDER ? "OK" : "Genders differ";123 comparison.NINumber = thefusionemployee.NationalId == thelegacyemployee.NATIONALID ? "OK" : "National Insurance numbers differ";124 comparison.UserName = thefusionemployee.UserName == thelegacyemployee.USERNAME ? "OK" : "Usernames differ";125 // End of creating comparator object126 if ( debugging ) {127 $('#legacyjsonheader').html('<h1>Legacy Employee Details for '+myperson+'</h1>');128 $('#fusionjsonheader').html('<h1>Fusion Employee Details for '+myperson+'</h1>');129 $('#legacyreceivedjson').html(JSON.stringify(thelegacyemployee));130 $('#fusionreceivedjson').html(JSON.stringify(thefusionemployee));131 }132 // Now fill out Handlebars template table133 var context = {134 model: thefusionemployee,135 other: thelegacyemployee,136 comparison: comparison137 };138 var theTemplateScript = $("#comparator-template").html();139 // console.log(theTemplateScript);140 var theTemplate = Handlebars.compile(theTemplateScript);141 debugwrite("After compile");142 // Clear out the display area143 $("#main").empty();144 $("#main").append(theTemplate(context));145}146// ============================================================================147// Needs refactoring to use getLegacyEmployee and get FusionEmployee148function generateComparisonSpreadsheet() {149 console.log("generateComparisonSpreadsheet called");150 // Outer getJSON call for legacy store151 var legacyurl = baseLegacyURL + "48";152 var legacylist = new Array();153 var theperson; // Tne current person we are dealing with154 var index = 0;155 var comparisonSummary = new Array(); // Holds all results of comparisons for all people156 // Set up fixed array of person id's to prove concept of the157 // further logic below.158 legacylist = [5500018, 5500215, 5500165, 6704306];159 var summarylength = legacylist.length;160 // Set up loop to iterate over returned legacy list161 for (var i=0; i<summarylength; i++) {162 // Get person code163 theperson = legacylist[i];164 console.log("Comparing " + theperson + " ...");165 mylegacy = getLegacyEmployee(theperson);166 console.log("mylegacy ");167 console.table(mylegacy);168 myfusion = getFusionEmployee(theperson);169 console.log("myfusion ");170 console.table(myfusion);171 if ( mylegacy && myfusion) {172 console.log("Adding " + theperson + " to comparisonSummary");173 mycomparison = comparePeople(mylegacy, myfusion);174 comparisonSummary.push(mycomparison);175 }176 };177 downloadCSV({ data: comparisonSummary, filename: "ComparisonSummary.csv" });178}179// ============================================================================180function getLegacyEmployee(legacyemployee) {181 var result = new Object();182 /*183 result = {"TITLE":"MRS.","FORENAME":"Keira","SURNAME":"Grobstein","PREFERREDNAME":null,"PERSONNUMBER":5500165,"HOMEPHONENUMBER":null,"WORKEMAIL":"e.grobstein@yopmail.com","ADDRESSLINE1":"55 Tagwell Road","ADDRESSLINE3":null,"ADDRESSLINE4":null,"CITY":"Droitwich","REGION":"Worcestershire","COUNTRY":null,"POSTALCODE":"WR9 7AQ","DATEOFBIRTH":"1971-04-26","ETHNICITY":"White-British","GENDER":"F","NATIONALID":"NX707818A","USERNAME":"QUEENNM"}184 */185 var myperson = legacyemployee || 5500165;186 var legacyurl = baseLegacyURL + baselegacyqueryid + "&p1=";187 var jsonstring; // Used for legacy employee data188 legacyurl += myperson;189 $.getJSON(legacyurl, function (data) {190 // console.log("Legacy url: "+url);191 jsonstring = JSON.stringify(data[0]);192 // jsonstring = new String('{"legacydata:"' + jsonstring + '}').toString();193 // debugwrite("Legacy jsonstring: "+jsonstring);194 result = JSON.parse(jsonstring);195 });196 return ( result );197}198// ============================================================================199function getFusionEmployee(fusionemployee) {200 var thefusionemployee = fusionemployee || 5500165;201 var result = new Object();202 /*203 result = {"Title":"MRS.","FirstName":"Keira","LastName":"Grobstein","PreferredName":null,"PersonNumber":5500165,"HomePhoneNumber":null,"WorkEmail":"e.grobstein@yopmail.com","AddressLine1":"55 Tagwell Road","AddressLine2":null,"AddressLine3":null,"City":"Droitwich","Region":"Worcestershire","Country":null,"PostalCode":"WR9 7AQ","DateOfBirth":"1971-04-26","Ethnicity":"White-British","Gender":"F","NationalId":"NX707818A","UserName":"QUEENNM"};204 */205 var fusionurl = baseCoreURL + "emps?onlyData&limit=10000&q=PersonNumber=" + thefusionemployee;206 var jsonstring2; // Used for Fusion employee data207 // Now issue AJAX call to get fusion employee details208 $.ajax({209 type: "GET",210 url: fusionurl,211 dataType: "json",212 headers: {"Authorization": "Basic " + btoa("TECHADMIN6:Banzai29")},213 success: function(data) {214 jsonstring2 = JSON.stringify(data.items[0]);215 // debugwrite("Fusion jsonstring2: "+jsonstring2);216 result = JSON.parse(jsonstring2);217 },218 error: function(xhr, textStatus, errorThrown) {219 $('#error').html(xhr.responseText);220 return (null);221 }222 }); // end of ajax call223 return ( result );224}225// ============================================================================226function comparePeople(legacy, fusion) {227 // Now set up comparator object228 var comparison = {};229 comparison.PersonID = legacy.PERSONNUMBER;230 // Must apply developed transforms before doing Y/N comparison231 var dummy = fusionTitleCode({oldtitlecode: legacy.TITLE});232 comparison.Title = fusion.Salutation == dummy ? "Y" : "N";233 comparison.Forename = fusion.FirstName == legacy.FORENAME ? "Y" : "N";234 comparison.Surname = fusion.LastName == legacy.SURNAME ? "Y" : "N";235 comparison.Preferredname = fusion.PreferredName == legacy.PREFERREDNAME ? "Y" : "N";236 comparison.PersonCode = fusion.PersonNumber == legacy.PERSONNUMBER ? "Y" : "N";237 comparison.HomeTelephone = fusion.HomeTelephone == legacy.HOMEPHONENUMBER ? "Y" : "N";238 comparison.WorkEmail = fusion.WorkEmail == legacy.WORKEMAIL ? "Y" : "N";239 // Now do checks on address components240 var addressmessage = "";241 addressmessage += fusion.AddressLine1 == legacy.ADDRESSLINE1 ? "" : " line 1 different,";242 addressmessage += fusion.AddressLine2 == legacy.ADDRESSLINE2 ? "" : " line 2 different,";243 addressmessage += fusion.AddressLine3 == legacy.ADDRESSLINE3 ? "" : " line 3 different,";244 addressmessage += fusion.City == legacy.CITY ? "" : " town different,";245 addressmessage += fusion.Region == legacy.REGION ? "" : " region different,";246 addressmessage += fusion.Country == legacy.COUNTRY ? "" : " country different,";247 addressmessage += fusion.PostalCode == legacy.POSTALCODE ? "" : " postcode different,";248 comparison.Address = addressmessage == "" ? "Y" : "N";249 // End of address components checks250 comparison.DateOfBirth = fusion.DateOfBirth == legacy.DATEOFBIRTH ? "Y" : "N";251 dummy = fusionEthnicityCode({oldethnicdescription: legacy.ETHNICITY});252 comparison.Ethnicity = fusion.Ethnicity == dummy ? "Y" : "N";253 comparison.Gender = fusion.Gender == legacy.GENDER ? "Y" : "N";254 comparison.NINumber = fusion.NationalId == legacy.NATIONALID ? "Y" : "N";255 comparison.UserName = fusion.UserName == legacy.USERNAME ? "Y" : "N";256 return ( comparison );257}258// ============================================================================259function runTestSuite() {260 var mylegacy = new Object();261 var myfusion = new Object();262 var mycomparison = new Object();263 var comparisonSummary = new Array();264 var theperson;265 paramSetup(); // Set up parameters for run from submitting form.266 // For testingh purposes, set up short list of person IDs267 var legacylist = [5500018, 5500215, 5500165, 6704306];268 var summarylength = legacylist.length;269 // Set up loop to iterate over returned legacy list270 for (var i=0; i<summarylength; i++) {271 theperson = legacylist[i];272 console.log("Comparing " + theperson + " ...");273 mylegacy = getLegacyEmployee(theperson);274 console.log("mylegacy ");275 console.table(mylegacy);276 myfusion = getFusionEmployee(theperson);277 console.log("myfusion ");278 console.table(myfusion);279 if ( mylegacy && myfusion) {280 console.log("Adding " + theperson + " to comparisonSummary");281 mycomparison = comparePeople(mylegacy, myfusion);282 comparisonSummary.push(mycomparison);283 }284 myfusion= {};285 mylegacy = {};286 console.table(comparisonSummary);287 } // end of for loop288} // end of function definition289$(document).ready(function() {290 // ===========================================291 // Single Employee Comparison292 $('#personcomparator').click( function(event) {293 event.preventDefault();294 paramSetup();295 generateEmployeeComparisonTable();296 });297 // ===========================================298 // Comparison Spreadsheet299 $('#comparisonspreadsheet').click( function(event) {300 event.preventDefault();301 paramSetup(); // Pull in run parameters from submission form302 generateComparisonSpreadsheet();303 }); // end of click event for #comparisonspreadsheet304 // ===========================================305 // Test suite306 $('#functiontest').click( function(event) {307 event.preventDefault();308 runTestSuite();309 }); // end of click event for #functiontest...
CheckWorker.js
Source:CheckWorker.js
1//2// CheckWorker.js3//4// All Javascript routines to generate all segments of a a Worker.dat5// as separate files6//7// Normally called from CheckWorker.asp8//9// Global variables10// legacysource: from submitting form - will determine which legacy query to run.11// fusionsource: eventually from submitting form to determine which Fusion environment12// to go to for the employee information. Contsant at DEV URL's for now.13// legacyqueryid: for selecting which query to run. Dependent on legacysource.14//15var defaultlegacyqueryid = "?id=49";16var baseCoreURL = "https://edzz-test.hcm.em3.oraclecloud.com/hcmCoreApi/resources/11.12.1.0/";17var baseLegacyURL = "http://its-n-jcnc-01/UoB/fetchJSON.asp";18var curperson = 5500165;19var debugging = true;20var comparisonSummary = new Object();21// ============================================================================22function debugwrite(text) {23 if ( debugging ) {24 console.log(text);25 }26}27// ============================================================================28function paramSetup() {29 var whichlegacy;30 var whichfusion;31 var debugchoice;32 // Fetch parameters from CheckWorker.asp form33 curperson = $('#personcode').val();34 whichlegacy = $('#legacysystem').val();35 whichfusion = $('#targetsystem').val();36 debugchoice = $('#debugmode').val();37 // Establish debugging mode38 if ( debugchoice == "Y" ) {39 debugging = true;40 } else {41 debugging=false;42 }43 debugwrite("Values from CheckWorker form before any checks or defaults applied:");44 debugwrite(curperson);45 debugwrite(whichlegacy);46 debugwrite(whichfusion);47 debugwrite(debugchoice);48 var thelegacyemployee = "";49 var thefusionemployee = "";50 curperson = curperson || 5500165;51 // Construct appropriate starting Fusion url52 baseCoreURL = "https://"+whichfusion+".hcm.em3.oraclecloud.com/hcmCoreApi/resources/11.12.1.0/";53 // Construct appropriate starting legacy URL54 if ( whichlegacy == "ACCESS") {55 baseLegacyURL = "http://its-n-jcnc-01/UoB/fetchJSON.asp";56 }57 if ( whichlegacy == "ALTAHRN") {58 baseLegacyURL = "http://its-n-jcnc-01/UoB/fetchALTA.asp";59 }60 // Adjust URLs to reflect submitted person code (in curperson)61}62// ============================================================================63function generateEmployeeComparisonTable() {64 var myperson = curperson || '5500165';65 var fusionurl = baseCoreURL + "emps?onlyData&limit=10000&q=PersonNumber=";66 var legacyurl = baseLegacyURL + "?id=49&p1=";67 var nullobjectstring = "{}";68 var nullobject = {};69 var thefusionemployee = {};70 var thelegacyemployee = {};71 debugwrite("Calling paramSetup");72 paramSetup();73 debugwrite("After paramSetup");74 legacyurl += myperson;75 fusionurl += myperson;76 // debugwrite(legacyurl);77 // debugwrite(fusionurl);78 // blank out raw JSON divs even if not in debug mode to clear screen79 $('#legacyjsonheader').html('');80 $('#legacyreceivedjson').html('');81 $('#fusionjsonheader').html('');82 $('#fusionreceivedjson').html('');83 // Get legacy data first84 var jsonstring; // Used for legacy employee data85 var jsonstring2; // Used for Fusion employee data86 $.getJSON(legacyurl, function (data) {87 // console.log("Legacy url: "+url);88 jsonstring = JSON.stringify(data[0]);89 // jsonstring = new String('{"legacydata:"' + jsonstring + '}').toString();90 // debugwrite("Legacy jsonstring: "+jsonstring);91 thelegacyemployee =JSON.parse(jsonstring);92 // Now issue AJAX call to get fusion employee details93 $.ajax({94 type: "GET",95 url: fusionurl,96 dataType: "json",97 headers: {"Authorization": "Basic " + btoa("TECHADMIN6:Banzai29")},98 success: function(data) {99 jsonstring2 = JSON.stringify(data.items[0]);100 // debugwrite("Fusion jsonstring2: "+jsonstring2);101 thefusionemployee =JSON.parse(jsonstring2);102 // Now reinitialise comparator object103 // Look through legacy and fusion data filling in differences104 // in comparator object105 var comparison = {};106 // Must apply developed transforms before doing Y/N comparison107 var dummy = fusionTitleCode(thelegacyemployee.TITLE);108 comparison.Title = thefusionemployee.Salutation == dummy ? "OK" : "Titles differ";109 comparison.Forename = thefusionemployee.FirstName == thelegacyemployee.FORENAME ? "OK" : "Forenames differ";110 comparison.Surname = thefusionemployee.LastName == thelegacyemployee.SURNAME ? "OK" : "Surnames differ";111 comparison.Preferredname = thefusionemployee.PreferredName == thelegacyemployee.PREFERREDNAME ? "OK" : "Preferred names differ";112 comparison.PersonCode = thefusionemployee.PersonNumber == thelegacyemployee.PERSONNUMBER ? "OK" : "Person ID's differ";113 comparison.HomeTelephone = thefusionemployee.HomeTelephone == thelegacyemployee.HOMEPHONENUMBER ? "OK" : "Home telephone numbers differ";114 comparison.WorkEmail = thefusionemployee.WorkEmail == thelegacyemployee.WORKEMAIL ? "OK" : "Titles differ";115 // Now do checks on address components116 var addressmessage = "";117 addressmessage += thefusionemployee.AddressLine1 == thelegacyemployee.ADDRESSLINE1 ? "" : " line 1 different,";118 addressmessage += thefusionemployee.AddressLine2 == thelegacyemployee.ADDRESSLINE2 ? "" : " line 2 different,";119 addressmessage += thefusionemployee.AddressLine3 == thelegacyemployee.ADDRESSLINE3 ? "" : " line 3 different,";120 addressmessage += thefusionemployee.City == thelegacyemployee.CITY ? "" : " town different,";121 addressmessage += thefusionemployee.Region == thelegacyemployee.REGION ? "" : " region different,";122 addressmessage += thefusionemployee.Country == thelegacyemployee.COUNTRY ? "" : " country different,";123 addressmessage += thefusionemployee.PostalCode == thelegacyemployee.POSTALCODE ? "" : " postcode different,";124 comparison.Address = addressmessage == "" ? "OK" : "Addresses differ:"+addressmessage;125 // End of address components checks126 comparison.DateOfBirth = thefusionemployee.DateOfBirth == thelegacyemployee.DATEOFBIRTH ? "OK" : "Dates of birth differ";127 dummy = fusionEthnicityCode(thelegacyemployee.ETHNICITY);128 comparison.Ethnicity = thefusionemployee.Ethnicity == dummy ? "OK" : "Ethnicities differ";129 comparison.Gender = thefusionemployee.Gender == thelegacyemployee.GENDER ? "OK" : "Genders differ";130 comparison.NINumber = thefusionemployee.NationalId == thelegacyemployee.NATIONALID ? "OK" : "National Insurance numbers differ";131 comparison.UserName = thefusionemployee.UserName == thelegacyemployee.USERNAME ? "OK" : "Usernames differ";132 // End of creating comparator object133 if ( debugging ) {134 $('#legacyjsonheader').html('<h1>Legacy Employee Details for '+myperson+'</h1>');135 $('#fusionjsonheader').html('<h1>Fusion Employee Details for '+myperson+'</h1>');136 $('#legacyreceivedjson').html(jsonstring);137 $('#fusionreceivedjson').html(jsonstring2);138 }139 // Now fill out Handlebars template table140 var context = {141 model: thefusionemployee,142 other: thelegacyemployee,143 comparison: comparison144 };145 var theTemplateScript = $("#comparator-template").html();146 // console.log(theTemplateScript);147 var theTemplate = Handlebars.compile(theTemplateScript);148 debugwrite("After compile");149 // Clear out the display area150 $("#main").empty();151 $("#main").append(theTemplate(context));152 },153 error: function(xhr, textStatus, errorThrown) {154 $('#error').html(xhr.responseText);155 return (null);156 }157 }); // end of ajax call158 });159}160// ============================================================================161function compareEmployee(personcode) {162 var myperson = personcode || '5500165';163 var fusionurl = baseCoreURL + "emps?onlyData&limit=10000&q=PersonNumber=";164 var legacyurl = baseLegacyURL + "?id=49&p1=";165 var nullobjectstring = "{}";166 var nullobject = {};167 var summarylength = 0;168 var fusion = {};169 var legacy = {};170 // Now reinitialise comparator object171 var comparison = {};172 legacyurl += myperson;173 fusionurl += myperson;174 // Look through legacy and fusion data filling in differences175 // in comparator object176 // Get legacy data first177 var jsonstring; // Used for legacy employee data178 var jsonstring2; // Used for Fusion employee data179 $.getJSON(legacyurl, function (data) {180 // console.log("Legacy url: "+url);181 jsonstring = JSON.stringify(data[0]);182 // jsonstring = new String('{"legacydata:"' + jsonstring + '}').toString();183 // debugwrite("Legacy jsonstring: "+jsonstring);184 legacy = JSON.parse(jsonstring);185 // Now issue AJAX call to get fusion employee details186 $.ajax({187 type: "GET",188 url: fusionurl,189 dataType: "json",190 headers: {"Authorization": "Basic " + btoa("TECHADMIN6:Banzai29")},191 success: function(data) {192 jsonstring2 = JSON.stringify(data.items[0]);193 // debugwrite("Fusion jsonstring2: "+jsonstring2);194 fusion = JSON.parse(jsonstring2);195 comparison.PersonID = legacy.PERSONNUMBER;196 // Must apply developed transforms before doing Y/N comparison197 var dummy = fusionTitleCode(legacy.TITLE);198 comparison.Title = fusion.Salutation == dummy ? "Y" : "N";199 comparison.Forename = fusion.FirstName == legacy.FORENAME ? "Y" : "N";200 comparison.Surname = fusion.LastName == legacy.SURNAME ? "Y" : "N";201 comparison.Preferredname = fusion.PreferredName == legacy.PREFERREDNAME ? "Y" : "N";202 comparison.PersonCode = fusion.PersonNumber == legacy.PERSONNUMBER ? "Y" : "N";203 comparison.HomeTelephone = fusion.HomeTelephone == legacy.HOMEPHONENUMBER ? "Y" : "N";204 comparison.WorkEmail = fusion.WorkEmail == legacy.WORKEMAIL ? "Y" : "N";205 // Now do checks on address components206 var addressmessage = "";207 addressmessage += fusion.AddressLine1 == legacy.ADDRESSLINE1 ? "" : " line 1 different,";208 addressmessage += fusion.AddressLine2 == legacy.ADDRESSLINE2 ? "" : " line 2 different,";209 addressmessage += fusion.AddressLine3 == legacy.ADDRESSLINE3 ? "" : " line 3 different,";210 addressmessage += fusion.City == legacy.CITY ? "" : " town different,";211 addressmessage += fusion.Region == legacy.REGION ? "" : " region different,";212 addressmessage += fusion.Country == legacy.COUNTRY ? "" : " country different,";213 addressmessage += fusion.PostalCode == legacy.POSTALCODE ? "" : " postcode different,";214 comparison.Address = addressmessage == "" ? "Y" : "N";215 // End of address components checks216 comparison.DateOfBirth = fusion.DateOfBirth == legacy.DATEOFBIRTH ? "Y" : "N";217 dummy = fusionEthnicityCode(legacy.ETHNICITY);218 comparison.Ethnicity = fusion.Ethnicity == dummy ? "Y" : "N";219 comparison.Gender = fusion.Gender == legacy.GENDER ? "Y" : "N";220 comparison.NINumber = fusion.NationalId == legacy.NATIONALID ? "Y" : "N";221 comparison.UserName = fusion.UserName == legacy.USERNAME ? "Y" : "N";222 // console.log("Inner ajax loop end for " + personcode + "- comparison object");223 // console.log( comparison );224 },225 error: function(xhr, textStatus, errorThrown) {226 $('#error').html(xhr.responseText);227 return (null);228 }229 }); // end of ajax call230 // console.log("Outside ajax but inside getJSON loops in compareEmployee for " + personcode + "- comparison object");231 // console.log( comparison );232 // This does not return correctly to calling function even though it is233 // correctly filled up here!!!!234 });235 // console.log("Outside all AJAX loops in compareEmployee for " + personcode + "- comparison object");236 // console.log( comparison );237 return ( comparison );238}239// ============================================================================240function generateComparisonSpreadsheet() {241 console.log("generateComparisonSpreadsheet called");242 // Outer getJSON call for legacy store243 var legacyurl = baseLegacyURL + "?id=48";244 var legacylist = new Array();245 var theperson; // Tne current person we are dealing with246 var index = 0;247 var comparisonSummary = new Array(); // Holds all results of comparisons for all people248 // console.log(legacyurl);249 // console.log(typeof legacylist);250 /*251 $.ajax({252 url: legacyurl,253 dataType: 'json',254 error: function(xhr, textStatus, errorThrown) {255 $('#error').html(xhr.responseText);256 return (null);257 },258 success: function(data) {259 $.each(data, function(item) {260 theperson = this.PersonCode;261 console.log(theperson+" - "+typeof theperson);262 legacylist[index] = new Number(theperson).valueOf();263 index++;264 });265 }266 });267 // End 1st JSON loop268 console.log("End of legacy JSON loop - legacylist = ");269 console.log(typeof legacylist);270 */271 // Set up fixed array of person id's to prove concept of the272 // further logic below.273 legacylist = [5500018, 5500215, 5500165, 6704306];274 var summarylength = legacylist.length;275 // Set up loop to iterate over returned legacy list276 for (var i=0; i<summarylength; i++) {277 // Get person code278 theperson = legacylist[i];279 // console.log(theperson);280 // Call compareEmployee for this person281 var mycomparison = compareEmployee(theperson);282 comparisonSummary.push(mycomparison);283 // console.log(mycomparison);284 // Add comparisons object from the compareEmployee return to285 // the summary array (comparisonSummary)286 // summarylength = comparisonSummary.push(mycomparison);287 };288 // Send summary array to file (.csv)289 // console.log("comparisonSummary");290 // console.log(comparisonSummary);291 downloadCSV({ data: comparisonSummary, filename: "ComparisonSummary.csv" });292}293$(document).ready(function() {294 // ===========================================295 // Single Employee Comparison296 $('#personcomparator').click( function(event) {297 event.preventDefault();298 paramSetup();299 generateEmployeeComparisonTable();300 });301 // ===========================================302 // Comparison Spreadsheet303 $('#comparisonspreadsheet').click( function(event) {304 event.preventDefault();305 paramSetup(); // Pull in run parameters from submission form306 generateComparisonSpreadsheet();307 }); // end of click event for #comparisonspreadsheet...
comparisonspreadsheetold.js
Source:comparisonspreadsheetold.js
1$('#comparisonspreadsheet').click( function(event) {2 event.preventDefault();3 // Set up parameters for this run.4 paramSetup();5 // Reinitialise comparisonSummary Array6 var comparisonSummary = new Array();7 var mycomparison = {};8 var summarylength = 0;9 var peopleList = new Array();10 console.log(debugging ? "We are in debug mode" : "We are in live mode");11 // Pick up list of people to look at12 //13 if (!debugging)14 {15 var legacyurl = baseLegacyURL + "?id=48";16 console.log(legacyurl);17 $.getJSON(legacyurl, function (legacydata) {18 // console.log("Data returned from getJSON call to legacy URL");19 // console.log(data);20 // console.log("Length of returned legacydata from getJSON");21 // console.log(legacydata.length);22 // console.log(legacydata.constructor === Array ? "legacydata is an Array" : "legacydata is NOT an Array");23 // console.log(legacydata[0]);24 // var jsonstring = JSON.stringify(legacydata);25 // jsonstring = new String("{allPeople:"+jsonstring+"}");26 // var peopledata = eval("("+jsonstring+")");27 // Set up array with list of person IDs28 var summarylength = 0;29 for (var i=0; i < legacydata.length; i++)30 {31 console.log(legacydata[i].PersonCode);32 peopleList[i] = legacydata[i].PersonCode;33 summarylength++;34 }35/*36 var dummy = 0;37 $.each(legacydata, function() {38 $.each(this, function() {39 // console.log(this.PersonCode);40 dummy = this.PersonCode;41 console.log(dummy);42 summarylength = peopleList.push(dummy);43 });44 });45*/46 });47 }48 else49 {50 peopleList = [5500018, 5500215, 5500165, 6704306];51 summarylength = 4;52 }53 console.log("List of people");54 console.log(peopleList);55 // console.log(peopleList.constructor === Array ? "peopleList is an Array" : "peopleList is NOT an Array");56 // Now loop through the set of people comparing each one and adding to resultset57 for (var i=0; i < summarylength; i++) {58 console.log("Comparing employee "+peopleList[i]);59 var mycomparison = compareEmployee(peopleList[i]);60 // console.log("Results from comparing "+peopleList[i]);61 // console.log(mycomparison);62 comparisonSummary.push(mycomparison);63 }64 if ( debugging ) {65 // console.log(comparisonSummary);66 // console.log("About to call downloadCSV");67 if ( debugging ) {68 $('#legacyjsonheader').html('<h1>Comparison matrix</h1>');69 $('#legacyreceivedjson').html();70 $('#legacyreceivedjson').html(JSON.stringify(comparisonSummary));71 }72 }73 // Write out summary spreadsheet74 downloadCSV({ data: comparisonSummary, filename: "ComparisonSummary.csv" });...
Using AI Code Generation
1var BestMatch = require('./models/bestMatch');2var bestMatch = new BestMatch();3var comparisonSummary = bestMatch.comparisonSummary();4console.log(comparisonSummary);5var BestMatch = require('./models/bestMatch');6var bestMatch = new BestMatch();7var comparisonSummary = bestMatch.comparisonSummary();8console.log(comparisonSummary);9var BestMatch = require('./models/bestMatch');10var bestMatch = new BestMatch();11var comparisonSummary = bestMatch.comparisonSummary();12console.log(comparisonSummary);13var BestMatch = require('./models/bestMatch');14var bestMatch = new BestMatch();15var comparisonSummary = bestMatch.comparisonSummary();16console.log(comparisonSummary);17var BestMatch = require('./models/bestMatch');18var bestMatch = new BestMatch();19var comparisonSummary = bestMatch.comparisonSummary();20console.log(comparisonSummary);21var BestMatch = require('./models/bestMatch');22var bestMatch = new BestMatch();23var comparisonSummary = bestMatch.comparisonSummary();24console.log(comparisonSummary);25var BestMatch = require('./models/bestMatch');26var bestMatch = new BestMatch();27var comparisonSummary = bestMatch.comparisonSummary();28console.log(comparisonSummary);29var BestMatch = require('./models/bestMatch');30var bestMatch = new BestMatch();31var comparisonSummary = bestMatch.comparisonSummary();32console.log(comparisonSummary);33var BestMatch = require('./models/bestMatch');34var bestMatch = new BestMatch();35var comparisonSummary = bestMatch.comparisonSummary();36console.log(comparisonSummary);37var BestMatch = require('./models/bestMatch
Using AI Code Generation
1var BestMatch = require('best-match');2var bm = new BestMatch();3var result = bm.comparisonSummary(['test1.js', 'test2.js', 'test3.js'], 'test4.js');4console.log(result);5#### new BestMatch()6#### .compare(a, b)7#### .comparisonSummary(list, string)8MIT © [Jon Schlinkert](
Using AI Code Generation
1var BestMatch = require("./BestMatch.js");2var bestMatch = new BestMatch();3var str1 = "This is a test string";4var str2 = "This is a test string";5var summary = bestMatch.comparisonSummary(str1, str2);6console.log(summary);7var BestMatch = require("./BestMatch.js");8var bestMatch = new BestMatch();9var str1 = "This is a test string";10var str2 = "This is a test string";11var summary = bestMatch.comparisonSummary(str1, str2, true);12console.log(summary);13var BestMatch = require("./BestMatch.js");14var bestMatch = new BestMatch();15var str1 = "This is a test string";16var str2 = "This is a test string";17var summary = bestMatch.comparisonSummary(str1, str2, false);18console.log(summary);19var BestMatch = require("./BestMatch.js");20var bestMatch = new BestMatch();21var str1 = "This is a test string";22var str2 = "This is a test string";23var summary = bestMatch.comparisonSummary(str1, str2, "hello");24console.log(summary);25var BestMatch = require("./BestMatch.js");26var bestMatch = new BestMatch();27var str1 = "This is a test string";28var str2 = "This is a test string";29var summary = bestMatch.comparisonSummary(str1, str2, 0);30console.log(summary);
Using AI Code Generation
1var BestMatch = require('./bestMatch.js');2var bestMatch = new BestMatch();3var input = ['A', 'B', 'C', 'D', 'E', 'F'];4var output = ['A', 'B', 'C', 'D', 'E', 'F'];5var summary = bestMatch.comparisonSummary(input, output);6console.log(summary);7var BestMatch = require('./bestMatch.js');8var bestMatch = new BestMatch();9var input = ['A', 'B', 'C', 'D', 'E', 'F'];10var output = ['A', 'B', 'C', 'D', 'E', 'F'];11var summary = bestMatch.comparisonSummary(input, output);12console.log(summary);13var BestMatch = require('./bestMatch.js');14var bestMatch = new BestMatch();15var input = ['A', 'B', 'C', 'D', 'E', 'F'];16var output = ['A', 'B', 'C', 'D', 'E', 'F'];17var summary = bestMatch.comparisonSummary(input, output);18console.log(summary);19var BestMatch = require('./bestMatch.js');20var bestMatch = new BestMatch();21var input = ['A', 'B', 'C', 'D', 'E', 'F'];22var output = ['A', 'B', 'C', 'D', 'E', 'F'];23var summary = bestMatch.comparisonSummary(input, output);24console.log(summary);25var BestMatch = require('./bestMatch.js');26var bestMatch = new BestMatch();27var input = ['A', 'B', 'C', 'D', 'E', 'F'];28var output = ['A', 'B', 'C', 'D', 'E', 'F'];29var summary = bestMatch.comparisonSummary(input, output);30console.log(summary);31var BestMatch = require('./bestMatch.js');32var bestMatch = new BestMatch();
Using AI Code Generation
1var BestMatch = require('best-match');2var bm = new BestMatch();3var input = "I like to play cricket";4var list = ["I like to play cricket","I like to play football","I like to play hockey","I like to play tennis","I like to play badminton"];5var result = bm.comparisonSummary(input,list);6console.log(result);7[ { score: 1, match: 'I like to play cricket' },8 { score: 0.5, match: 'I like to play football' },9 { score: 0.5, match: 'I like to play hockey' },10 { score: 0.4, match: 'I like to play tennis' },11 { score: 0.4, match: 'I like to play badminton' } ]
Using AI Code Generation
1var BestMatchFinder = require('./BestMatchFinder.js');2console.log("Test case 1");3var input1 = ["hello", "world", "london"];4var input2 = ["hi", "world", "london"];5var input3 = ["hello", "world", "london"];6var input4 = ["hello", "world", "london"];7var input5 = ["hello", "world", "london"];8var input6 = ["hello", "world", "london"];9var input7 = ["hello", "world", "london"];10var input8 = ["hello", "world", "london"];11var input9 = ["hello", "world", "london"];12var input10 = ["hello", "world", "london"];13var input11 = ["hello", "world", "london"];14var input12 = ["hello", "world", "london"];15var input13 = ["hello", "world", "london"];16var input14 = ["hello", "world", "london"];17var input15 = ["hello", "world", "london"];18var input16 = ["hello", "world", "london"];19var input17 = ["hello", "world", "london"];20var input18 = ["hello", "world", "london"];21var input19 = ["hello", "world", "london"];22var input20 = ["hello", "world", "london"];23var input21 = ["hello", "world", "london"];24var input22 = ["hello", "world", "london"];25var input23 = ["hello", "world", "london"];26var input24 = ["hello", "world", "london"];27var input25 = ["hello", "world", "london"];28var input26 = ["hello", "world", "london"];29var input27 = ["hello", "world", "london"];30var input28 = ["hello", "world", "london"];31var input29 = ["hello", "world", "london"];32var input30 = ["hello", "world", "london"];33var input31 = ["hello", "world", "london"];34var input32 = ["hello", "world", "london"];35var input33 = ["hello", "world", "london"];
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!