Parentcustomer bei Kontakt mit SOAP setzen ?

08/06/2009 - 16:44 von mhammen | Report spam
Hallo zusammen,

wie kann man mit einem SOAP-Aufruf beim Kontakt die Firma setzen ?
wenn ich einfach nur im XML
"<parentcustomerid>"+accountid+"</parentcustomerid>"
mitgebe, passiert bei mir nix. ?
gibt es noch einen Tag, um Mitzuteilen, dass es sich um eine Firma
beim Parent handelt ?
Oder gibt es andere Sachen zu beachten ?

Viele Grüße
Matthias
 

Lesen sie die antworten

#1 mhammen
09/06/2009 - 09:59 | Warnen spam
ok, um mein Problem etwas deutlicher darzustellen:
Ich habe ein Objekt, bei dem ich im onLoad eine Funktion für das
onSave-Event habe.
Das Objekt ist ein Custom-Dummy-Objekt, in welchem die User sowohl
Firmendaten als auch Kontaktdaten als auch ein weiteres (Custom)-
Objekt eingeben können.
Damit wollen wir das leidige öffnen von 3-4 Masken ersparen, da CRM ja
nur ein Objekt pro Eingabemaske annehmen kann.
In diesem Script will ich analog den Beispielen aus dem SDK mit
Javascript und SOAP-Aufrufen erst Firma, dann Kontakt zur Firma, und
dann das Custom-Objekt (in 2 Auspràgungen) erstellen.
Die Objekte werden auch brav erstellt. Bis auf den Link des Kontaktes
zur Firma. Ebenso bei den anderen Custom-Objekten.

Der Code im onLoad sieht so aus:


OnSave_Account = function()
{
var oIsSavingPossible = false;
// Ist Formular Online?
if (IsOnline())
{
var addresscheck =true;

// Firmaname
var companyname= crmForm.all.mmi_name.DataValue;
companyname = encodeURIComponent(companyname);
// Strasse
var street = crmForm.all.mmi_strasse1.DataValue;
street= encodeURIComponent(street);
// Postleitzahl
var zipcode = crmForm.all.mmi_plz.DataValue;
zipcode = encodeURIComponent(zipcode);
// Stadt
var city = crmForm.all.mmi_ort.DataValue;
city = encodeURIComponent(city);
// Land
var country = crmForm.all.mmi_land.SelectedText;
country = encodeURIComponent(country);

// Hausnummer
var streetnumber = "";
if (crmForm.all.mmi_hausnummer!=null &&
crmForm.all.mmi_hausnummer.DataValue != null)
{ streetnumber=crmForm.all.mmi_hausnummer.DataValue;}
streetnumber=encodeURIComponent(streetnumber);

// Bundesland
var county = "";
var adressid = "";
var kundenid = "";

var para ="?land=" +country;
para += "&stadt="+city;
para += "&plz="+zipcode;
para += "&strasse="+street;
para += "&companyname="+companyname;
para += "&adressid="+adressid;
para += "&kundenid="+kundenid;
para += "&hausnummer="+streetnumber;
para += "&bundesland="+county;

var url = "/ISV/Resco.Mmi.Crm4.Webapplication/CheckAddress.aspx" +
para;
var ret = openStdDlg(url,null,800,600);
var msg ="Wollen Sie trotzdem Speichern ohne Adressencheck?";
var save = "";

if (ret!=null)
{
var strasse = "";
var hausnummer = "";
var ort = "";
var plz = "";
var bundesland = "";

//var res="";
for (var j = 0; j < ret.length; j++)
{
//res += ret[j].id+ "|" + ret[j].value + ", ";
if (ret[j].id == "save") save = ret[j].value;
if (ret[j].id == "strasse") strasse = ret[j].value;
if (ret[j].id == "ort") ort = ret[j].value;
if (ret[j].id == "plz") plz = ret[j].value;
if (ret[j].id == "bundesland") bundesland = ret[j].value;
if (ret[j].id == "hausnummer") hausnummer = ret[j].value;
}

// Abfangen, um was es sich handelt dublette/standard
if (strasse != "")
{ crmForm.all.mmi_strasse1.DataValue = strasse; }

if (plz != "")
{ crmForm.all.mmi_plz.DataValue = plz;}
if (ort != "")
{ crmForm.all.mmi_ort.DataValue = ort;}
if (hausnummer != "")
{ crmForm.all.mmi_hausnummer.DataValue = hausnummer;}
if (bundesland != "")
{ //crmForm.all.address1_stateorprovince.DataValue = bundesland;
}
crmForm.all.mmi_checked.DataValue = (save.toLowerCase()
=="true");
oIsSavingPossible = (save.toLowerCase()=="true");

//erzeuge Kundendatensatz
companyname = crmForm.all.mmi_name.DataValue;
var companyname2 = "";
if (crmForm.all.mmi_kundenname2!=null &&
crmForm.all.mmi_kundenname2.DataValue != null)
{ companyname2=crmForm.all.mmi_kundenname2.DataValue;}
// Strasse
street= crmForm.all.mmi_strasse1.DataValue;
// Postleitzahl
zipcode = crmForm.all.mmi_plz.DataValue;
// Stadt
city = crmForm.all.mmi_ort.DataValue;
//city = encodeURIComponent(crmForm.all.mmi_ort.DataValue);
// Land
country = crmForm.all.mmi_land.DataValue;

// Hausnummer
var streetnumber = "";
if (crmForm.all.mmi_hausnummer!=null &&
crmForm.all.mmi_hausnummer.DataValue != null)
{ streetnumber=crmForm.all.mmi_hausnummer.DataValue;}
//Telefon
var telephone=""
if (crmForm.all.mmi_telefonzentral!=null &&
crmForm.all.mmi_telefonzentral.DataValue != null)
{ telephone=crmForm.all.mmi_telefonzentral.DataValue;}
//Email
var email=""
if (crmForm.all.mmi_emailzentral!=null &&
crmForm.all.mmi_emailzentral.DataValue != null)
{ email=crmForm.all.mmi_emailzentral.DataValue;}
//Sprache
var sprache=""
if (crmForm.all.mmi_sprache!=null &&
crmForm.all.mmi_sprache.DataValue != null)
{ sprache=crmForm.all.mmi_sprache.DataValue;}


var authenticationHeader = GenerateAuthenticationHeader();
var 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'>"+authenticationHeader
+
"<soap:Body><Create xmlns='http://schemas.microsoft.com/crm/2007/
WebServices'>"+
"<entity xsi:type='account'>"+
"<name>"+companyname+"</name>"+
"<mmi_kundenname2>"+companyname2+"</mmi_kundenname2>"+
"<address1_line1>"+strasse+"</address1_line1>"+
"<address1_postalcode>"+zipcode+"</address1_postalcode>"+
"<mmi_land>"+country+"</mmi_land>"+
"<address1_city>"+city+"</address1_city>"+
"<address1_county>"+streetnumber+"</address1_county>"+
"<address1_telephone1>"+telephone+"</address1_telephone1>"+
"<emailaddress1>"+email+"</emailaddress1>"+
"<new_sprache>"+sprache+"</new_sprache>"+
"</entity></Create></soap:Body></soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/
2007/WebServices/Create");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//
description').nodeTypedValue;
alert(msg);
}
// Open new contact record if no errors.
else
{
var accountid = resultXml.selectSingleNode("//CreateResult");
crmForm.all.mmi_account.DataValue=accountid;
//window.open("/sfa/accts/edit.aspx?id={"+accountid.nodeTypedValue
+"}");
}
// Kontaktanlage

anrede = crmForm.all.mmi_anrede.DataValue;
vorname = crmForm.all.mmi_vorname.DataValue;
nachname = crmForm.all.mmi_nachname.DataValue;

// Telefon
var telefongesch = "";
if (crmForm.all.mmi_telefongeschftlich!=null &&
crmForm.all.mmi_telefongeschftlich.DataValue != null)
{ telefongesch=crmForm.all.mmi_telefongeschftlich.DataValue;}
var email=""
if (crmForm.all.mmi_telefonzentral!=null &&
crmForm.all.mmi_telefonzentral.DataValue != null)
{ telephone=crmForm.all.mmi_telefonzentral.DataValue;}
//Email
var email2=""
if (crmForm.all.mmi_email!=null && crmForm.all.mmi_email.DataValue !null)
{ email2=crmForm.all.mmi_email.DataValue;}
//AkadTitel
var akadTitel=""
if (crmForm.all.mmi_akadtitel!=null &&
crmForm.all.mmi_akadtitel.DataValue != null)
{ akadTitel=crmForm.all.mmi_akadtitel.DataValue;}

var authenticationHeader = GenerateAuthenticationHeader();
var 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'>"+authenticationHeader
+
"<soap:Body><Create xmlns='http://schemas.microsoft.com/crm/2007/
WebServices'>"+
"<entity xsi:type='contact'>"+
"<lastname>"+nachname+"</lastname>"+
"<firstname>"+vorname+"</firstname>"+
"<gendercode>"+anrede+"</gendercode>"+
"<mmi_kundenname2>"+companyname2+"</mmi_kundenname2>"+
"<address1_line1>"+strasse+"</address1_line1>"+
"<address1_postalcode>"+zipcode+"</address1_postalcode>"+
"<mmi_land>"+country+"</mmi_land>"+
"<address1_city>"+city+"</address1_city>"+
"<address1_county>"+streetnumber+"</address1_county>"+
"<telephone1>"+telefongesch+"</telephone1>"+
"<emailaddress1>"+email2+"</emailaddress1>"+
"<mmi_sprache>"+sprache+"</mmi_sprache>"+
"<parentcustomerid>"+accountid+"</parentcustomerid>"+
"<accountid>"+accountid+"</accountid>"+
"</entity></Create></soap:Body></soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/
2007/WebServices/Create");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//
description').nodeTypedValue;
alert(msg);
}
else
{
var contactid = resultXml.selectSingleNode("//CreateResult");
}

// Veranstaltungsanlage 1
var veranstaltung=crmForm.all.mmi_veranstaltung.DataValue;

var authenticationHeader = GenerateAuthenticationHeader();
var 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'>"+authenticationHeader
+
"<soap:Body><Create xmlns='http://schemas.microsoft.com/crm/2007/
WebServices'>"+
"<entity xsi:type='mmi_veranstaltung'>"+
"<mmi_name>"+crmForm.all.mmi_veranstaltung.SelectedText+"</
mmi_name>"+
"<mmi_firmaid>"+accountid+"</mmi_firmaid>"+
"<mmi_veranstaltungpick>"+veranstaltung+"</mmi_veranstaltungpick>"+
"</entity></Create></soap:Body></soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/
2007/WebServices/Create");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//
description').nodeTypedValue;
alert(msg);
}
// Open new contact record if no errors.
else
{
var veranstaltungsid1= resultXml.selectSingleNode("//
CreateResult");
//window.open("/sfa/accts/edit.aspx?id={"+accountid.nodeTypedValue
+"}");
}
// Veranstaltungsanlage 2
var authenticationHeader = GenerateAuthenticationHeader();
var 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'>"+authenticationHeader
+
"<soap:Body><Create xmlns='http://schemas.microsoft.com/crm/2007/
WebServices'>"+
"<entity xsi:type='mmi_veranstaltung'>"+
"<mmi_name>"+crmForm.all.mmi_veranstaltung.SelectedText+"</
mmi_name>"+
"<mmi_kontaktid>"+contactid+"</mmi_kontaktid>"+
"<mmi_veranstaltungpick>"+veranstaltung+"</mmi_veranstaltungpick>"+
"</entity></Create></soap:Body></soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/
2007/WebServices/Create");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode('//
description').nodeTypedValue;
alert(msg);
}
else
{
var veranstaltungsid2 = resultXml.selectSingleNode("//
CreateResult");
window.open("/userdefined/edit.aspx?id{"+veranstaltungsid2.nodeTypedValue+"}&etc002");
}

}
else
{
crmForm.all.mmi_checked.DataValue = false;
alert("Fehler: Es kann nicht gespeichert werden!");
oIsSavingPossible = false;
event.returnValue = false;
}
if (crmForm.all.mmi_firmaffnen.DataValue == true)
{window.open("/sfa/accts/edit.aspx?id={"+accountid.nodeTypedValue
+"}");}
event.returnValue = oIsSavingPossible;
return oIsSavingPossible;
}
}

Ähnliche fragen