I am having a hard time wrapping my head around how i can manipulate the stack in JS Hopefully this exercise will help me..
So im trying write a function that makes a soap xml call and parses the data. Then returns the parsed data when called.
I can get it to console.log the result when i call the function, but i can not get it to return the result so i can store it in a variable ect.. It returns undefined.
Code Below:
var request = require('request');
var DOMParser = require('xmldom').DOMParser;
function query (entity,field,op,expression,elementToParse){
   xml = 
        `<?xml version="1.0" encoding="utf-8"?>
           <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:xsd="http://www.w3.org/2001/XMLSchema">
           <soap:Header>
           <AutotaskIntegrations xmlns="http://autotask.net/ATWS/v1_6/">
           <IntegrationCode>H2FATPVKPDN25IXIBSMN5K66XAA</IntegrationCode>
           </AutotaskIntegrations>
           </soap:Header>
           <soap:Body>
           <query xmlns="http://autotask.net/ATWS/v1_6/">
           <sXML><![CDATA[<queryxml><entity>${entity}</entity><query><field>${field}<expression 
           op="${op}">${expression}</expression></field></query></queryxml>]]></sXML>
           </query>
           </soap:Body>
           </soap:Envelope>`;
   options = {
      'method': 'POST',
      'url': 'https://webservices15.autotask.net/ATServices/1.6/atws.asmx',
      'headers': {
         'Content-Type': 'text/xml',
         'Authorization':'Auth Goes Here'
      },
      body: xml
      };
    request(options, function (error, response) { 
      if (error) throw new Error(error);
       text =  response.body;
       parser =  new DOMParser();
       xmlDoc =  parser.parseFromString(text,"text/xml");
       xmlResult = xmlDoc.getElementsByTagName(`${elementToParse}`)[0].childNodes[0].nodeValue;
       **console.log(xmlResult)**
      });
}
query('Ticket','TicketNumber','BeginsWith','T2019','id') 
// returns result if i log the data in REQUEST
//returns undefined otherwise
 
    