Skip to content

Instantly share code, notes, and snippets.

@notgosu
Created November 28, 2016 14:22
Show Gist options
  • Save notgosu/98af0b7a14c3cd2096dfab7c403181ad to your computer and use it in GitHub Desktop.
Save notgosu/98af0b7a14c3cd2096dfab7c403181ad to your computer and use it in GitHub Desktop.
public static function CreateLead($authHeader, $url)
{
$newName = "Test-name-vintage";
$email = "vintage@vintage.com.ua";
$phone = "111111111";
$desc = '';
$lang = '';
$pageUrl = '';
$formData = '(100000001, 100000000)';
$productUrl = '';
$quantity = 0;
$source = '';
$companyType = '(100000003)';
$newId = "00000000-0000-0000-0000-000000000000";
try {
$xml = "<s:Body>";
$xml .= "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
$xml .= "<request i:type=\"a:CreateRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" >";
$xml .= "<a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>Target</b:key>";
$xml .= "<b:value i:type=\"a:Entity\">";
$xml .= "<a:Attributes>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>firstname</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" . $newName . "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>emailaddress1</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" . $email . "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>mobilephone</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" . $phone . "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>description</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" . $desc . "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>new_language</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" . $lang . "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>new_page_url</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" . $pageUrl . "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>new_form_id</b:key>";
$xml .= "<b:value i:type='a:OptionSetValue'>";
$xml .= "<a:value>" . $formData . "</a:value>";
$xml .= "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>new_product</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" . $productUrl . "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>new_quantity</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" . $quantity . "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>new_source</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" . $source . "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>new_companytype</b:key>";
$xml .= "<b:value i:type='a:OptionSetValue'>";
$xml .= "<a:value>" . $companyType . "</a:value>";
$xml .= "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "</a:Attributes>";
$xml .= "<a:EntityState i:nil=\"true\" />";
$xml .= "<a:FormattedValues xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\" />";
$xml .= "<a:Id>" . $newId . "</a:Id>";
$xml .= "<a:LogicalName>lead</a:LogicalName>";
$xml .= "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "</a:Parameters>";
$xml .= "<a:RequestId i:nil=\"true\" />";
$xml .= "<a:RequestName>Create</a:RequestName>";
$xml .= "</request>";
$xml .= "</Execute>";
$xml .= "</s:Body>";
$executeSoap = new CrmExecuteSoap ();
$response = $executeSoap->ExecuteSOAPRequest ( $authHeader, $xml, $url );
var_dump($response);exit;
} catch (\Exception $e) {
echo 'Выброшено исключение: ', $e->getMessage(), "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment