private void SendEmailFromTemplate()
{
CrmService service = connect();
// Create the 'From:' activity party for the email
activityparty fromParty = new activityparty();
fromParty.partyid = new Lookup();
fromParty.partyid.type = EntityName.systemuser.ToString();
fromParty.partyid.Value = new Guid("4D52A946-AE37-DE11-B372-000C29DF4A76");
// Create the 'To:' activity party for the email
activityparty toParty = new activityparty();
toParty.partyid = new Lookup();
toParty.partyid.type = EntityName.account.ToString();
toParty.partyid.Value = new Guid("B835890F-E23E-DE11-ACC7-000C29DF4A76");
// Create an email message.
email email = new email();
// Set email properties
email.to = new activityparty[] { toParty };
email.from = new activityparty[] { fromParty };
email.subject = "SDK Sample email";
email.description = "SDK Sample for SendEmailFromTemplate Message.";
CrmBoolean direction = new CrmBoolean();
direction.Value = true;
email.directioncode = direction;
TargetSendFromTemplateEmail emailTemplateTarget = new TargetSendFromTemplateEmail();
emailTemplateTarget.Email = email;
SendEmailFromTemplateRequest emailRequest = new SendEmailFromTemplateRequest();
emailRequest.Target = emailTemplateTarget;
// The regarding Id is requried and must be of the same type as the Email Template
emailRequest.RegardingId = new Guid("B835890F-E23E-DE11-ACC7-000C29DF4A76");
emailRequest.RegardingType = EntityName.account.ToString();
// Use a built-in email template of type "contact".
emailRequest.TemplateId = new Guid("B6C38BB9-2423-471D-8B38-E3B99ED80E7A");
SendEmailFromTemplateResponse emailResponse = (SendEmailFromTemplateResponse)service.Execute(emailRequest);
}
Saturday, July 18, 2009
Send saved email activity / Message form crm 4.0 / 3.0
private void SendEmail(Guid emailActId)
{
#region Create and SendEmail request.
SendEmailRequest req = new SendEmailRequest();
req.EmailId = emailActId;
req.TrackingToken = "";
req.IssueSend = true;
// Send the email message.
SendEmailResponse res = (SendEmailResponse)service.Execute(req);
#endregion
}
{
#region Create and SendEmail request.
SendEmailRequest req = new SendEmailRequest();
req.EmailId = emailActId;
req.TrackingToken = "";
req.IssueSend = true;
// Send the email message.
SendEmailResponse res = (SendEmailResponse)service.Execute(req);
#endregion
}
Friday, July 17, 2009
Add / Upload attachment to Email activity in CRM 4.0/ 3.0
public void AddAttachmentToEmailActivity(string emailActId, string PDFFileNameName)
{
//Add an attachment
string currentPath = txtPath.Text;
Directory.SetCurrentDirectory(currentPath );
// Check to see if File exists
activitymimeattachment attachment = new activitymimeattachment();
if (File.Exists(currentPath + "\\" + PDFFileNameName.ToString() + ".pdf"))
{
// Get mimeType for File extension
string ext = System.IO.Path.GetExtension(currentPath + "\\" + PDFFileNameName.ToString() + ".pdf").ToLower();
string mimeType = string.Empty;
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (regKey != null && regKey.GetValue("Content Type") != null)
mimeType = regKey.GetValue("Content Type").ToString();
//New Filestream Code for MS Word .doc and .docx extensions and PDF files .pdf extension
FileInfo pointer = new FileInfo(currentPath + "\\" + PDFFileNameName.ToString() + ".pdf");
FileStream fileStream = pointer.OpenRead();
byte[] byteData = new byte[(int)fileStream.Length];
fileStream.Read(byteData, 0, (int)fileStream.Length);
string encodedData = System.Convert.ToBase64String(byteData);
fileStream.Flush();
fileStream.Close();
attachment.activityid = new Lookup();
attachment.activityid.Value =new Guid(emailActId);
attachment.activityid.type = EntityName.email.ToString();
attachment.filename = PDFFileNameName.ToString() + ".pdf";
attachment.attachmentnumber = new CrmNumber();
attachment.attachmentnumber.Value = 1;
attachment.body = encodedData;
attachment.mimetype = mimeType;
service = CLM_CRM_Service.GetCrmService();
// Create the Attachment in CRM.
Guid attachmentId = service.Create(attachment);
}
}
{
//Add an attachment
string currentPath = txtPath.Text;
Directory.SetCurrentDirectory(currentPath );
// Check to see if File exists
activitymimeattachment attachment = new activitymimeattachment();
if (File.Exists(currentPath + "\\" + PDFFileNameName.ToString() + ".pdf"))
{
// Get mimeType for File extension
string ext = System.IO.Path.GetExtension(currentPath + "\\" + PDFFileNameName.ToString() + ".pdf").ToLower();
string mimeType = string.Empty;
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (regKey != null && regKey.GetValue("Content Type") != null)
mimeType = regKey.GetValue("Content Type").ToString();
//New Filestream Code for MS Word .doc and .docx extensions and PDF files .pdf extension
FileInfo pointer = new FileInfo(currentPath + "\\" + PDFFileNameName.ToString() + ".pdf");
FileStream fileStream = pointer.OpenRead();
byte[] byteData = new byte[(int)fileStream.Length];
fileStream.Read(byteData, 0, (int)fileStream.Length);
string encodedData = System.Convert.ToBase64String(byteData);
fileStream.Flush();
fileStream.Close();
attachment.activityid = new Lookup();
attachment.activityid.Value =new Guid(emailActId);
attachment.activityid.type = EntityName.email.ToString();
attachment.filename = PDFFileNameName.ToString() + ".pdf";
attachment.attachmentnumber = new CrmNumber();
attachment.attachmentnumber.Value = 1;
attachment.body = encodedData;
attachment.mimetype = mimeType;
service = CLM_CRM_Service.GetCrmService();
// Create the Attachment in CRM.
Guid attachmentId = service.Create(attachment);
}
}
Create Email activity for CRM 4.0 form C#.net
public void CreateEmailActivity(string accountId, string PDFFileNameName, string invoiceId)
{
string[] splitName = PDFFileNameName.Split('-'); //Larry & Susan Craven - Invoice Processed For Month - Jan 2009.pdf
string[] splitExt = splitName[2].Split('.');
service = CLM_CRM_Service.GetCrmService();
email actpointer = new email();
actpointer.subject = "Christian Life Ministry - " + splitName[1].ToString() + " - " + splitExt[0].ToString();
actpointer.description = "body";
Guid ow = new Guid(ownerID.ToString());
actpointer.ownerid = new Owner();
actpointer.ownerid.type = EntityName.systemuser.ToString();
actpointer.ownerid.Value = ow;
activityparty party = new activityparty();
party.partyid = new Lookup();
party.partyid.type = EntityName.systemuser.ToString();
party.partyid.Value = ow;
actpointer.from = new activityparty[] { party };
Guid ow1 = new Guid(accountId.ToString());
activityparty party1 = new activityparty();
party1.partyid = new Lookup();
party1.partyid.type = EntityName.account.ToString();
party1.partyid.Value = ow1;
actpointer.to = new activityparty[] { party1 };
Guid ow2 = new Guid(invoiceId.ToString());
Lookup lookup = new Lookup();
lookup.Value = ow2;
lookup.type = EntityName.invoice.ToString();
actpointer.regardingobjectid = lookup;
Guid emailActId = service.Create(actpointer);
AddAttachmentToEmailActivity(emailActId.ToString(), PDFFileNameName);
}
{
string[] splitName = PDFFileNameName.Split('-'); //Larry & Susan Craven - Invoice Processed For Month - Jan 2009.pdf
string[] splitExt = splitName[2].Split('.');
service = CLM_CRM_Service.GetCrmService();
email actpointer = new email();
actpointer.subject = "Christian Life Ministry - " + splitName[1].ToString() + " - " + splitExt[0].ToString();
actpointer.description = "body";
Guid ow = new Guid(ownerID.ToString());
actpointer.ownerid = new Owner();
actpointer.ownerid.type = EntityName.systemuser.ToString();
actpointer.ownerid.Value = ow;
activityparty party = new activityparty();
party.partyid = new Lookup();
party.partyid.type = EntityName.systemuser.ToString();
party.partyid.Value = ow;
actpointer.from = new activityparty[] { party };
Guid ow1 = new Guid(accountId.ToString());
activityparty party1 = new activityparty();
party1.partyid = new Lookup();
party1.partyid.type = EntityName.account.ToString();
party1.partyid.Value = ow1;
actpointer.to = new activityparty[] { party1 };
Guid ow2 = new Guid(invoiceId.ToString());
Lookup lookup = new Lookup();
lookup.Value = ow2;
lookup.type = EntityName.invoice.ToString();
actpointer.regardingobjectid = lookup;
Guid emailActId = service.Create(actpointer);
AddAttachmentToEmailActivity(emailActId.ToString(), PDFFileNameName);
}
Code to connect to CRM meta service
public static MetadataService.MetadataService GetMetaService()
{
#region for Online
CrmDiscoveryService.CrmDiscoveryService discoveryService = new CrmDiscoveryService.CrmDiscoveryService();
discoveryService.Url = String.Format("https://{0}/MSCRMServices/2007/{1}/CrmDiscoveryService.asmx", "dev.crm.dynamics.com", "Passport");
RetrievePolicyRequest policyRequest = new RetrievePolicyRequest();
RetrievePolicyResponse policyResponse = (RetrievePolicyResponse)discoveryService.Execute(policyRequest);
LogonManager lm = new LogonManager();
string passportTicket = lm.Logon(ConfigurationSettings.AppSettings["CRMUserName"], ConfigurationSettings.AppSettings["CRMPassword"], "crm.dynamics.com", policyResponse.Policy, "Production");
lm.Dispose();
RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
crmTicketRequest.OrganizationName = ConfigurationSettings.AppSettings["Organization"];
crmTicketRequest.PassportTicket = passportTicket;
RetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse)discoveryService.Execute(crmTicketRequest);
MetadataService.MetadataService mdService =new CLMApplication.MetadataService.MetadataService();
mdService.Url = crmTicketResponse.OrganizationDetail.CrmMetadataServiceUrl;
MetadataService.CrmAuthenticationToken token = new MetadataService.CrmAuthenticationToken();
token.AuthenticationType = AuthenticationType.Passport;
token.CrmTicket = crmTicketResponse.CrmTicket;
token.OrganizationName = crmTicketResponse.OrganizationDetail.OrganizationName;
mdService.CrmAuthenticationTokenValue = token;
//CrmService myService = objConfig.RetrieveService();
//CreateDynamiceEntity(mdService, myService);
#endregion
return mdService;
}
{
#region for Online
CrmDiscoveryService.CrmDiscoveryService discoveryService = new CrmDiscoveryService.CrmDiscoveryService();
discoveryService.Url = String.Format("https://{0}/MSCRMServices/2007/{1}/CrmDiscoveryService.asmx", "dev.crm.dynamics.com", "Passport");
RetrievePolicyRequest policyRequest = new RetrievePolicyRequest();
RetrievePolicyResponse policyResponse = (RetrievePolicyResponse)discoveryService.Execute(policyRequest);
LogonManager lm = new LogonManager();
string passportTicket = lm.Logon(ConfigurationSettings.AppSettings["CRMUserName"], ConfigurationSettings.AppSettings["CRMPassword"], "crm.dynamics.com", policyResponse.Policy, "Production");
lm.Dispose();
RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
crmTicketRequest.OrganizationName = ConfigurationSettings.AppSettings["Organization"];
crmTicketRequest.PassportTicket = passportTicket;
RetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse)discoveryService.Execute(crmTicketRequest);
MetadataService.MetadataService mdService =new CLMApplication.MetadataService.MetadataService();
mdService.Url = crmTicketResponse.OrganizationDetail.CrmMetadataServiceUrl;
MetadataService.CrmAuthenticationToken token = new MetadataService.CrmAuthenticationToken();
token.AuthenticationType = AuthenticationType.Passport;
token.CrmTicket = crmTicketResponse.CrmTicket;
token.OrganizationName = crmTicketResponse.OrganizationDetail.OrganizationName;
mdService.CrmAuthenticationTokenValue = token;
//CrmService myService = objConfig.RetrieveService();
//CreateDynamiceEntity(mdService, myService);
#endregion
return mdService;
}
Code to connect to CRM Online CRMService
you have to down load service and store it on hard disk and add reference to it in application.
public static CrmService.CrmService GetCrmService()
{
if (CLMservice == null)
{
CLMservice = new CrmService.CrmService();
//CrmAuthenticationToken token1 = new CrmAuthenticationToken();
//token1.AuthenticationType = 0;
//token1.OrganizationName = "CLM";
//CLMservice.CrmAuthenticationTokenValue = token1;
//CLMservice.Credentials = new System.Net.NetworkCredential("administrator", "syspro15*TX");
//
//-------------------
CrmDiscoveryService.CrmDiscoveryService discoveryService = new CrmDiscoveryService.CrmDiscoveryService();
discoveryService.Url = String.Format("https://{0}/MSCRMServices/2007/{1}/CrmDiscoveryService.asmx", "dev.crm.dynamics.com", "Passport");
//"http://clm.crm.dynamics.com/MSCrmServices/2007/Passport/CrmDiscoveryService.asmx?uniquename=clm";//
RetrievePolicyRequest policyRequest = new RetrievePolicyRequest();
RetrievePolicyResponse policyResponse = (RetrievePolicyResponse)discoveryService.Execute(policyRequest);
LogonManager lm = new LogonManager();
//string passportTicket = lm.Logon("syspro101@hotmail.com", "dxt31MS", "crm.dynamics.com", policyResponse.Policy, "Production");
// string passportTicket = lm.Logon("crmadmin@sysprotech.com", "sys35adm", "crm.dynamics.com", policyResponse.Policy, "Production");
string passportTicket = lm.Logon(ConfigurationSettings.AppSettings["CRMUserName"], ConfigurationSettings.AppSettings["CRMPassword"], "crm.dynamics.com", policyResponse.Policy, "Production");
RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
//crmTicketRequest.OrganizationName = "clm";
crmTicketRequest.OrganizationName = ConfigurationSettings.AppSettings["Organization"];
//crmTicketRequest.OrganizationName = System.Configuration.ConfigurationSettings.AppSettings["Orgname"];
crmTicketRequest.PassportTicket = passportTicket;
RetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse)discoveryService.Execute(crmTicketRequest);
CrmService.CrmService crmService = new CrmService.CrmService();
crmService.Url = crmTicketResponse.OrganizationDetail.CrmServiceUrl;
CrmService.CrmAuthenticationToken token = new CrmService.CrmAuthenticationToken();
token.AuthenticationType = AuthenticationType.Passport;
token.CrmTicket = crmTicketResponse.CrmTicket;
token.OrganizationName = crmTicketResponse.OrganizationDetail.OrganizationName;
crmService.CrmAuthenticationTokenValue = token;
WhoAmIRequest whoRequest = new WhoAmIRequest();
WhoAmIResponse whoResponse = (WhoAmIResponse)crmService.Execute(whoRequest);
lm.Dispose();
CrmService.CrmService service = crmService;
CLMservice = crmService;
return CLMservice;// service;
}
return CLMservice;
}
public static CrmService.CrmService GetCrmService()
{
if (CLMservice == null)
{
CLMservice = new CrmService.CrmService();
//CrmAuthenticationToken token1 = new CrmAuthenticationToken();
//token1.AuthenticationType = 0;
//token1.OrganizationName = "CLM";
//CLMservice.CrmAuthenticationTokenValue = token1;
//CLMservice.Credentials = new System.Net.NetworkCredential("administrator", "syspro15*TX");
//
//-------------------
CrmDiscoveryService.CrmDiscoveryService discoveryService = new CrmDiscoveryService.CrmDiscoveryService();
discoveryService.Url = String.Format("https://{0}/MSCRMServices/2007/{1}/CrmDiscoveryService.asmx", "dev.crm.dynamics.com", "Passport");
//"http://clm.crm.dynamics.com/MSCrmServices/2007/Passport/CrmDiscoveryService.asmx?uniquename=clm";//
RetrievePolicyRequest policyRequest = new RetrievePolicyRequest();
RetrievePolicyResponse policyResponse = (RetrievePolicyResponse)discoveryService.Execute(policyRequest);
LogonManager lm = new LogonManager();
//string passportTicket = lm.Logon("syspro101@hotmail.com", "dxt31MS", "crm.dynamics.com", policyResponse.Policy, "Production");
// string passportTicket = lm.Logon("crmadmin@sysprotech.com", "sys35adm", "crm.dynamics.com", policyResponse.Policy, "Production");
string passportTicket = lm.Logon(ConfigurationSettings.AppSettings["CRMUserName"], ConfigurationSettings.AppSettings["CRMPassword"], "crm.dynamics.com", policyResponse.Policy, "Production");
RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
//crmTicketRequest.OrganizationName = "clm";
crmTicketRequest.OrganizationName = ConfigurationSettings.AppSettings["Organization"];
//crmTicketRequest.OrganizationName = System.Configuration.ConfigurationSettings.AppSettings["Orgname"];
crmTicketRequest.PassportTicket = passportTicket;
RetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse)discoveryService.Execute(crmTicketRequest);
CrmService.CrmService crmService = new CrmService.CrmService();
crmService.Url = crmTicketResponse.OrganizationDetail.CrmServiceUrl;
CrmService.CrmAuthenticationToken token = new CrmService.CrmAuthenticationToken();
token.AuthenticationType = AuthenticationType.Passport;
token.CrmTicket = crmTicketResponse.CrmTicket;
token.OrganizationName = crmTicketResponse.OrganizationDetail.OrganizationName;
crmService.CrmAuthenticationTokenValue = token;
WhoAmIRequest whoRequest = new WhoAmIRequest();
WhoAmIResponse whoResponse = (WhoAmIResponse)crmService.Execute(whoRequest);
lm.Dispose();
CrmService.CrmService service = crmService;
CLMservice = crmService;
return CLMservice;// service;
}
return CLMservice;
}
Add Invoice to Product in CRM 4.0 with write in existing Product
Guid productId = new Guid(productid);
invoicedetail objDetails = new invoicedetail();
objDetails.productid = new Lookup();
objDetails.productid.Value = productId;
objDetails.productid.type = EntityName.product.ToString();
//if (!string.IsNullOrEmpty(product.description))
//{
// objDetails.description = product.description.ToString();
//}
CrmDecimal objDec = new CrmDecimal();
objDec.Value = Convert.ToDecimal("1", CultureInfo.InvariantCulture);
objDetails.quantity = objDec;
CrmMoney objDec1 = new CrmMoney();
objDec1.Value = Convert.ToDecimal(allocatedAmount, CultureInfo.InvariantCulture);
objDetails.priceperunit = objDec1;
objDetails.invoiceid = new Lookup();
objDetails.invoiceid.Value = invoiceId;
objDetails.invoiceid.type = EntityName.invoice.ToString();
CrmBoolean objOverride = new CrmBoolean();
objOverride.Value = true;//
objDetails.ispriceoverridden = objOverride;
CrmBoolean objProductOverride = new CrmBoolean();
objProductOverride.Value = false;//
// objDetails.ispriceoverridden = objOverride;
objDetails.isproductoverridden = objProductOverride;
objDetails.uomid = new Lookup();
objDetails.uomid.Value = new Guid(RetrieveUog());
objDetails.uomid.type = EntityName.uom.ToString();
service.Create(objDetails);
invoicedetail objDetails = new invoicedetail();
objDetails.productid = new Lookup();
objDetails.productid.Value = productId;
objDetails.productid.type = EntityName.product.ToString();
//if (!string.IsNullOrEmpty(product.description))
//{
// objDetails.description = product.description.ToString();
//}
CrmDecimal objDec = new CrmDecimal();
objDec.Value = Convert.ToDecimal("1", CultureInfo.InvariantCulture);
objDetails.quantity = objDec;
CrmMoney objDec1 = new CrmMoney();
objDec1.Value = Convert.ToDecimal(allocatedAmount, CultureInfo.InvariantCulture);
objDetails.priceperunit = objDec1;
objDetails.invoiceid = new Lookup();
objDetails.invoiceid.Value = invoiceId;
objDetails.invoiceid.type = EntityName.invoice.ToString();
CrmBoolean objOverride = new CrmBoolean();
objOverride.Value = true;//
objDetails.ispriceoverridden = objOverride;
CrmBoolean objProductOverride = new CrmBoolean();
objProductOverride.Value = false;//
// objDetails.ispriceoverridden = objOverride;
objDetails.isproductoverridden = objProductOverride;
objDetails.uomid = new Lookup();
objDetails.uomid.Value = new Guid(RetrieveUog());
objDetails.uomid.type = EntityName.uom.ToString();
service.Create(objDetails);
Add product to Invoice (Write In Product)
invoicedetail objDetails = new invoicedetail();
CrmBoolean objProductOverride = new CrmBoolean();
objProductOverride.Value = true;//
objDetails.isproductoverridden = objProductOverride;
productName = ConfigurationSettings.AppSettings["ProductLineItem_Prefix"].ToString() + " - " + dt_kidsSupported.Rows[kd]["KidName"].ToString();
objDetails.productdescription = productName;
CrmDecimal objDec = new CrmDecimal();
objDec.Value = Convert.ToDecimal("1", CultureInfo.InvariantCulture);
objDetails.quantity = objDec;
CrmMoney objDec1 = new CrmMoney();
objDec1.Value = SponsordAmount;
objDetails.priceperunit = objDec1;
objDetails.invoiceid = new Lookup();
objDetails.invoiceid.Value = invoiceId;
objDetails.invoiceid.type = EntityName.invoice.ToString();
service.Create(objDetails);
CrmBoolean objProductOverride = new CrmBoolean();
objProductOverride.Value = true;//
objDetails.isproductoverridden = objProductOverride;
productName = ConfigurationSettings.AppSettings["ProductLineItem_Prefix"].ToString() + " - " + dt_kidsSupported.Rows[kd]["KidName"].ToString();
objDetails.productdescription = productName;
CrmDecimal objDec = new CrmDecimal();
objDec.Value = Convert.ToDecimal("1", CultureInfo.InvariantCulture);
objDetails.quantity = objDec;
CrmMoney objDec1 = new CrmMoney();
objDec1.Value = SponsordAmount;
objDetails.priceperunit = objDec1;
objDetails.invoiceid = new Lookup();
objDetails.invoiceid.Value = invoiceId;
objDetails.invoiceid.type = EntityName.invoice.ToString();
service.Create(objDetails);
Create Invoice in CRM 4.0 / 3.0
service = CLM_CRM_Service.GetCrmService();
invoice objInvoice = new invoice();
invioceName = accountName + " - Invoice Processed For Month - " + critiria[0].ToString() + " " + critiria[1].ToString();
objInvoice.name = invioceName;
Customer customerid = new Customer();
customerid.Value = new Guid(accountId);
customerid.type = EntityName.account.ToString();
objInvoice.customerid = customerid;
objInvoice.ownerid = new Owner();
objInvoice.ownerid.Value = new Guid(ownerID); // new Guid("C3182C2C-C266-DE11-A541-001E0B5E0BF6");//system userid
objInvoice.ownerid.type = EntityName.systemuser.ToString();
objInvoice.pricelevelid = new Lookup();
objInvoice.pricelevelid.Value = new Guid(RetrievePriceLevel());
objInvoice.pricelevelid.type = EntityName.pricelevel.ToString();
CrmBoolean objSync = new CrmBoolean();
objSync.Value = true;
objInvoice.new_issynchronized = objSync;
Guid invoiceId = service.Create(objInvoice);
invoice objInvoice = new invoice();
invioceName = accountName + " - Invoice Processed For Month - " + critiria[0].ToString() + " " + critiria[1].ToString();
objInvoice.name = invioceName;
Customer customerid = new Customer();
customerid.Value = new Guid(accountId);
customerid.type = EntityName.account.ToString();
objInvoice.customerid = customerid;
objInvoice.ownerid = new Owner();
objInvoice.ownerid.Value = new Guid(ownerID); // new Guid("C3182C2C-C266-DE11-A541-001E0B5E0BF6");//system userid
objInvoice.ownerid.type = EntityName.systemuser.ToString();
objInvoice.pricelevelid = new Lookup();
objInvoice.pricelevelid.Value = new Guid(RetrievePriceLevel());
objInvoice.pricelevelid.type = EntityName.pricelevel.ToString();
CrmBoolean objSync = new CrmBoolean();
objSync.Value = true;
objInvoice.new_issynchronized = objSync;
Guid invoiceId = service.Create(objInvoice);
Retrieve / Access picklist items form CRM.
string st = GetPickListItemValue("account", "new_frequency", "Frequency");
public static string GetPickListItemValue(string entityName, string pickListName, string itemLabel)
{
string itemValue = string.Empty;
try
{
MetadataService.MetadataService service =new CLMApplication.MetadataService.MetadataService();
service = GetMetaService();
RetrieveAttributeRequest attribReq = new RetrieveAttributeRequest();
attribReq.EntityLogicalName = entityName;
attribReq.LogicalName = pickListName;
// Get the attribute metadata for the pickListName attribute.
RetrieveAttributeResponse amRes = (RetrieveAttributeResponse)service.Execute(attribReq);
AttributeMetadata am = amRes.AttributeMetadata;
PicklistAttributeMetadata listData = (PicklistAttributeMetadata)am;
foreach (Option option in listData.Options)
{
foreach (CLMApplication.MetadataService.LocLabel label in option.Label.LocLabels)
{
// Show US English value:label pairs
if (label.LanguageCode.Value == 1033)
//if (label.Label.Equals(itemLabel))
//{
//itemValue = option.Value.Value;
itemValue = itemValue + option.Value.Value.ToString() + ";";
itemValue = itemValue + option.Label.LocLabels[0].Label.ToString() + ",";
//}
}
}
}
catch (Exception ex)
{
}
return itemValue;
}
public static string GetPickListItemValue(string entityName, string pickListName, string itemLabel)
{
string itemValue = string.Empty;
try
{
MetadataService.MetadataService service =new CLMApplication.MetadataService.MetadataService();
service = GetMetaService();
RetrieveAttributeRequest attribReq = new RetrieveAttributeRequest();
attribReq.EntityLogicalName = entityName;
attribReq.LogicalName = pickListName;
// Get the attribute metadata for the pickListName attribute.
RetrieveAttributeResponse amRes = (RetrieveAttributeResponse)service.Execute(attribReq);
AttributeMetadata am = amRes.AttributeMetadata;
PicklistAttributeMetadata listData = (PicklistAttributeMetadata)am;
foreach (Option option in listData.Options)
{
foreach (CLMApplication.MetadataService.LocLabel label in option.Label.LocLabels)
{
// Show US English value:label pairs
if (label.LanguageCode.Value == 1033)
//if (label.Label.Equals(itemLabel))
//{
//itemValue = option.Value.Value;
itemValue = itemValue + option.Value.Value.ToString() + ";";
itemValue = itemValue + option.Label.LocLabels[0].Label.ToString() + ",";
//}
}
}
}
catch (Exception ex)
{
}
return itemValue;
}
Create Notes and attach document for Invoice in CRM 4.0 and 3.0
public void CreateNoteAndAddAttachment(string PDFFileNameName , string InvoiceId)
{
service = CLM_CRM_Service.GetCrmService();
//Read File
string currentPath = txtPath.Text;
FileStream stream = File.OpenRead(currentPath + "\\" + PDFFileNameName.ToString() + ".pdf");
byte[] byteData = new byte[stream.Length];
stream.Read(byteData, 0, byteData.Length);
stream.Close();
// Encode the data using base64.
string encodedData = System.Convert.ToBase64String(byteData);
annotation note = new annotation();
note.objectid = new Lookup();
note.objectid.type = EntityName.invoice.ToString();
note.objectid.Value = new Guid(InvoiceId);
note.objecttypecode = new EntityNameReference();
note.objecttypecode.Value = EntityName.invoice.ToString();
note.subject = PDFFileNameName.ToString();
// note.notetext = inviocePDFFileNameName.ToString();
note.documentbody = encodedData;
note.filename = PDFFileNameName.ToString() + ".pdf";
note.mimetype = @"application\pdf";
// Create the note.
Guid newNoteID = service.Create(note);
}
{
service = CLM_CRM_Service.GetCrmService();
//Read File
string currentPath = txtPath.Text;
FileStream stream = File.OpenRead(currentPath + "\\" + PDFFileNameName.ToString() + ".pdf");
byte[] byteData = new byte[stream.Length];
stream.Read(byteData, 0, byteData.Length);
stream.Close();
// Encode the data using base64.
string encodedData = System.Convert.ToBase64String(byteData);
annotation note = new annotation();
note.objectid = new Lookup();
note.objectid.type = EntityName.invoice.ToString();
note.objectid.Value = new Guid(InvoiceId);
note.objecttypecode = new EntityNameReference();
note.objecttypecode.Value = EntityName.invoice.ToString();
note.subject = PDFFileNameName.ToString();
// note.notetext = inviocePDFFileNameName.ToString();
note.documentbody = encodedData;
note.filename = PDFFileNameName.ToString() + ".pdf";
note.mimetype = @"application\pdf";
// Create the note.
Guid newNoteID = service.Create(note);
}
Subscribe to:
Posts (Atom)