2017-12-30 63 views
0

Ich bin versuchen Netsuite zu Salesforce mit Salesforce-SOAP-API (Partner WSDL) zu integrieren. In Netsuite Side i bin mit dem ‚N/https‘ Modul Anfrage und bekommen Antwort zu senden. Zuerst sende ich eine Login-Anfrage an Salesforce und es gibt die eindeutige Session-ID. Jetzt versuche ich Anfrage senden schaffen eine Konten Datensatz in Salesforce erstellen, um die erhaltenen Session-ID verwenden. Während der Konstruktion die XML SOAP-Nachricht, ich hinzufüge, den Session-ID-Wert in "urn: SessionId tag". die HTTPS-Anforderung beim Senden wird den folgenden SOAP-Fehlercode zeigt:Netsuite zu Salesforce-Integration: SOAP API Fehlercode: unerwartetes Element {} sessionId während einfacher Art Deserialisierung

Fehlermeldung:

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Client</faultcode><faultstring>Unexpected element {}sessionId during simple type deserialization</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>" 
    } 

My-Code:

Suite Script Version: 2.0, Type: Benutzerereignis, Methode: Nach dem Senden, Modul: 'N/https'

function afterSubmit(scriptContext) { 

var customerRec = scriptContext.newRecord ; 
var customerName = customerRec.getText('entityid'); 
log.debug('customerName : ',customerName); 


//SOAP Login Request 
var postData = ''; 
var header=[]; 
var apiURL = ''; 
var response = ''; 
var strSOAPLoginRequest=""; 
strSOAPLoginRequest += "<soapenv:Envelope xmlns:soapenv=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:urn=\"urn:partner.soap.sforce.com\">"; 
strSOAPLoginRequest += " <soapenv:Header>"; 
strSOAPLoginRequest += " <\/soapenv:Header>"; 
strSOAPLoginRequest += " <soapenv:Body>"; 
strSOAPLoginRequest += "  <urn:login>"; 
strSOAPLoginRequest += "   <urn:username>myloginid<\/urn:username>"; 
strSOAPLoginRequest += "   <urn:password>mypwd<\/urn:password>"; 
strSOAPLoginRequest += "  <\/urn:login>"; 
strSOAPLoginRequest += " <\/soapenv:Body>"; 
strSOAPLoginRequest += "<\/soapenv:Envelope>"; 

postData = strSOAPLoginRequest; 

header['Content-Type']='text/xml'; 
header['SOAPAction']='https://login.salesforce.com/services/Soap/u/41.0'; 
apiURL='https://login.salesforce.com/services/Soap/u/41.0'; 
try{ 

    response=https.post({ 
    url:apiURL, 
    headers:header, 
    body:postData 
    }); 

    response = JSON.stringify(response); 
    log.debug("Login-Respone:", response+ ', Type:'+typeof response); 

    var getSessionIdStartIndex = response.indexOf("<sessionId>"); 
    log.debug('getSessionIdStartIndex:',getSessionIdStartIndex); 
    var getSessionIdEndIndex = response.indexOf("</sessionId>"); 
    log.debug('getSessionIdEndIndex:',getSessionIdEndIndex); 

    var ressessionValue= response.substring(getSessionIdStartIndex, getSessionIdEndIndex); 
    ressessionValue = ressessionValue.replace(/^\s+|\s+$/g, ""); 
    log.debug('resSessionId:',ressessionValue + 'Type:'+typeof ressessionValue); 

    header = []; 

    // SOAP CREATE ACTION REQUEST 
    header['Content-Type']='text/xml'; 
    header['SOAPAction']= 'https://ap5.salesforce.com/services/Soap/u/41.0/00D7F0xxxx'; 
    apiURL='https://ap5.salesforce.com/services/Soap/u/41.0/'+'007xxxx'; 
    //apiURL=res_serverUrl; 
    var strSOAPCreateActionXml=""; 
    strSOAPCreateActionXml += "<soapenv:Envelope xmlns:soapenv=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:urn=\"urn:partner.soap.sforce.com\" xmlns:urn1=\"urn:sobject.partner.soap.sforce.com\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\">"; 
    strSOAPCreateActionXml += " <soapenv:Header>"; 
    strSOAPCreateActionXml += "  <urn:SessionHeader>"; 
    strSOAPCreateActionXml += "<urn:sessionId>"+ressessionValue+"<\/urn:sessionId>"; 
    strSOAPCreateActionXml += "<\/urn:sessionId>"; 
    strSOAPCreateActionXml += "  <\/urn:SessionHeader>"; 
    strSOAPCreateActionXml += " <\/soapenv:Header>"; 
    strSOAPCreateActionXml += " <soapenv:Body>"; 
    strSOAPCreateActionXml += "  <urn:create>"; 
    strSOAPCreateActionXml += "   <urn:sObjects xsi:type=\"urn1:Account\">"; 
    strSOAPCreateActionXml += "  <Name>"+customerName+"<\/Name>"; 
    strSOAPCreateActionXml += "  <AccountNumber>4567<\/AccountNumber>"; 
    strSOAPCreateActionXml += "  <\/urn:sObjects>"; 
    strSOAPCreateActionXml += "  <\/urn:create>"; 
    strSOAPCreateActionXml += " <\/soapenv:Body>"; 
    strSOAPCreateActionXml += "<\/soapenv:Envelope>"; 

    postData = strSOAPCreateActionXml; 

    var responseCreate = https.post({ 
     url:apiURL, 
     headers:header, 
     body:postData 
    }); 

    responseCreate = JSON.stringify(responseCreate); 
    log.debug("CreateAction-Respone:", responseCreate+ ', Type:'+typeof responseCreate); 

}catch(err){ 
    log.error('ERROR',err.message); 
} 

} 

Anstatt den sessionId-Wert wie im obigen Codeblock zuzuweisen. wenn i sessionId Wert Linie, wie in unten Codeblock ersetzt Mittel arbeitet es richtig

var strVar=""; 
strVar += " <urn:sessionId>AQ8AQJCeR3ViMdN48UXWfDD0SiMbW5K6JOz3a0K6DhXt63pp54PsKOpoiMh.8mnw7bJxe0hQoyrCbRZtk0kmliNFfIntRAQb<\/urn:sessionId>"; 

fragt sich, was der Fehler an Ort und Stelle ist der Wert für urn: sessionId Tag in meinem ersten Codeblock.

Meine Frage ist, wie die dynamisch erhielt Sitzungswert in der Konstruktions XML SOAP-Nachricht

Vielen Dank im Voraus zu konstruieren.

+1

Sieht aus wie Sie haben eine extra/urn: sessionId nicht sicher, dass das Problem ist –

+0

Hallo Kevin, ich habe keine zusätzliche Urne: SessionId-Element in XML-Soap-Nachricht. Der zweite Codeblock, ich erwähnte, weil, wenn Sie den Wert sessionId verwenden, einzelne Zeichenfolge innerhalb des Tags urn.sessionId hat. Es funktioniert korrekt. Beispiel: tyuugfdsssf '. Wenn ich so verwende, bedeutet das, dass es nicht funktioniert.Ex. '' + sessionId + ''. Vielen Dank –

Antwort

1

Sieht aus wie Sie benötigen: var getSessionIdStartIndex = response.indexOf ("<sessionId>") + ‚<sessionId>‘ .length;

Die Sitzungs-ID beginnt am Ende von <sessionId>.

Verwandte Themen