|  01.03.2010, 23:15 | #1 | 
| Участник | Crm 3.0: custom workflow create email from template 
			
			Добрый день, подскажите как создать email на основе шаблона хочется вместо X++: email email = new email(); email.trackingtoken = " "; activityparty fromparty = new activityparty(); fromparty.partyid = new Lookup(); fromparty.partyid.type = EntityName.systemuser.ToString(); fromparty.partyid.Value = userId; email.from = new activityparty[] {fromparty}; activityparty toparty = new activityparty(); toparty.partyid = new Lookup(); toparty.partyid.type = EntityName.account.ToString(); toparty.partyid.Value = accountId; email.to = new activityparty[] {toparty}; email.sender = emailSender; email.subject = emailSubj; email.description = emailDesc; email.ownerid = new Owner(); email.ownerid.type = EntityName.systemuser.ToString(); email.ownerid.Value = userId; Guid emailId = service.Create(email); X++: email email = new email();
email.CopyFromTemplate(templateId);
Guid emailId = service.Create(email); | 
|  | 
|  02.03.2010, 10:00 | #2 | 
| Moderator | 
			
			Используйте InstantiateTemplate Message // Set up the CRM Service. CrmService service = new CrmService(); service.Credentials = System.Net.CredentialCache.DefaultCredentials; // Create a template instantiation request. InstantiateTemplateRequest instTemplate = new InstantiateTemplateRequest(); // The email template to use. instTemplate.TemplateId = new Guid("9AF74EF9-A04C-DA11-A0C5-000D9DD8CDAC"); // The object that this email is regarding. instTemplate.ObjectId = new Guid("A0F2D8FE-6468-DA11-B748-000D9DD8CDAC"); instTemplate.ObjectType = EntityName.account.ToString(); //Uncomment this next line to return dynamic entities. //instTemplate.ReturnDynamicEntities = true; // Execute the request to create an email message from the template. InstantiateTemplateResponse instTemplateResponse = (InstantiateTemplateResponse)service.Execute(instTemplate); 
				__________________ http://fixrm.wordpress.com, снятие/наведение порчи. Быстро, дорого, гарантия.   MS Certified Dirty Magic Professional | 
|  | |
| За это сообщение автора поблагодарили: wb (1). | |
|  03.03.2010, 16:48 | #3 | 
| Участник | 
			
			спасибо. 1) Написал вот такой код X++: InstantiateTemplateRequest templateReq = new InstantiateTemplateRequest(); templateReq.TemplateId = templateId; templateReq.ObjectId = accountId; templateReq.ObjectType = EntityName.account.ToString(); templateReq.ReturnDynamicEntities = true; InstantiateTemplateResponse templateRes = (InstantiateTemplateResponse) service.Execute(templateReq); email email = (email) templateRes.BusinessEntityCollection.BusinessEntities[0]; email.trackingtoken = " "; email.ownerid = new Owner(); email.ownerid.type = EntityName.systemuser.ToString(); email.ownerid.Value = userId; Guid emailId = service.Create(email); X++: Error code = 8004280b.Unable to cast object of type 'CrmSdk.DynamicEntity' to type 'CrmSdk.email'. 2) насколько я понял к шаблону нельзя прикреплять файлы, т.е. шаблон письма будет без вложений, тогда где лучше сохранять вложения, чтобы их затем прикреплять к письмам? нельзя также в шаблон вставлять картинки (логотип)? | 
|  | 
|  03.03.2010, 17:07 | #4 | 
| Чайный пьяница | Цитата: 
		
			Сообщение от wb
			   спасибо. 1) Написал вот такой код X++: InstantiateTemplateRequest templateReq = new InstantiateTemplateRequest(); templateReq.TemplateId = templateId; templateReq.ObjectId = accountId; templateReq.ObjectType = EntityName.account.ToString(); templateReq.ReturnDynamicEntities = true; InstantiateTemplateResponse templateRes = (InstantiateTemplateResponse) service.Execute(templateReq); email email = (email) templateRes.BusinessEntityCollection.BusinessEntities[0]; email.trackingtoken = " "; email.ownerid = new Owner(); email.ownerid.type = EntityName.systemuser.ToString(); email.ownerid.Value = userId; Guid emailId = service.Create(email); X++: Error code = 8004280b.Unable to cast object of type 'CrmSdk.DynamicEntity' to type 'CrmSdk.email'. templateReq.ReturnDynamicEntities = false; Цитата: Попробуйте так. Правда в статье описывается Microsoft Dynamics CRM 4.0. Насчёт того подойдёт ли это под 3.0 - не могу сказать. 
				__________________ Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit | 
|  | |
| За это сообщение автора поблагодарили: wb (1). | |
|  03.03.2010, 17:47 | #5 | 
| Участник | 
			
			Спасибо. Теперь работает    Цитата: Может в Sales&Service Docs, но как программно их от туда достать? Цитата: 
		
			Сообщение от a33ik
			   Попробуйте так. Правда в статье описывается Microsoft Dynamics CRM 4.0. Насчёт того подойдёт ли это под 3.0 - не могу сказать.   Последний раз редактировалось wb; 03.03.2010 в 18:06. | 
|  | 
|  03.03.2010, 19:01 | #6 | 
| Чайный пьяница | Цитата: Вот этого не подскажу, потому что 3.0 видел в глаза пару раз, а опыт приобрёл уже на 4.0. Смотрите SDK по тройке. В самом шаблоне изначально картинки отображаются? Я помню вставлял как ссылки на picasa - и всё чудесно работало. Правда опять таки в 4.0. 
				__________________ Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit | 
|  | 
|  03.03.2010, 19:50 | #7 | 
| Участник | Цитата: нет, правда если установить курсор на место где должна быть картинка досвечивается пустая рамка | 
|  | 
|  04.03.2010, 00:02 | #8 | 
| Участник | 
			
			Чудеса для меня не понятные: код приведенный ниже отрабатывает без ошибок, письмо создается и отправляется успешно, но в прикрепленном письме пропадает вложение! X++: using (CrmService service = new CrmService()) { setServiceProperty(service); Guid salesliteratureId = new Guid(@"{5B852BEB-B626-DF11-A36C-000423D90837}"); Guid accountId = new Guid("{231EF12D-6A25-DF11-A36C-000423D90837}"); Guid userId = new Guid("{2D2AD46B-5321-DF11-9B70-000423D90837}"); Guid templateId = new Guid("{339A1896-B526-DF11-A36C-000423D90837}"); ColumnSet colsAccount = new ColumnSet(); colsAccount.Attributes = new string [] {"emailaddress1"}; account account = (account) service.Retrieve(EntityName.account.ToString(), accountId, colsAccount); if (account.emailaddress1.Length != 0) { InstantiateTemplateRequest templateReq = new InstantiateTemplateRequest(); templateReq.TemplateId = templateId; templateReq.ObjectId = accountId; templateReq.ObjectType = EntityName.account.ToString(); templateReq.ReturnDynamicEntities = false; InstantiateTemplateResponse templateRes = (InstantiateTemplateResponse) service.Execute(templateReq); email email = (email) templateRes.BusinessEntityCollection.BusinessEntities[0]; email.trackingtoken = " "; email.ownerid = new Owner(); email.ownerid.type = EntityName.systemuser.ToString(); email.ownerid.Value = userId; activityparty fromparty = new activityparty(); fromparty.partyid = new Lookup(); fromparty.partyid.type = EntityName.systemuser.ToString(); fromparty.partyid.Value = userId; email.from = new activityparty[] {fromparty}; activityparty toparty = new activityparty(); toparty.partyid = new Lookup(); toparty.partyid.type = EntityName.account.ToString(); toparty.partyid.Value = accountId; email.to = new activityparty[] {toparty}; Guid emailId = service.Create(email); Console.WriteLine("emailId=" + emailId.ToString()); BusinessEntityCollection entities; QueryExpression query = new QueryExpression(); query.EntityName = EntityName.salesliteratureitem.ToString(); ColumnSet cols = new ColumnSet(); cols.Attributes = new string[]{"filename", "title", "salesliteratureitemid", "mimetype"}; ConditionExpression condition = new ConditionExpression(); condition.AttributeName = "salesliteratureid"; condition.Values = new string[1]{salesliteratureId.ToString()}; condition.Operator = ConditionOperator.Equal; FilterExpression filter = new FilterExpression(); filter.Conditions = new ConditionExpression[] {condition}; query.ColumnSet = cols; query.Criteria = filter; entities = service.RetrieveMultiple(query); activitymimeattachment attach; if (entities.BusinessEntities.Length !=0) { System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Credentials = getNetworkCredential(); for(int i=0; i < entities.BusinessEntities.Length; i++) { salesliteratureitem entity = (salesliteratureitem)entities.BusinessEntities[i]; string attachmentUrl = getAttachmentUrl(entity.salesliteratureitemid.Value); byte[] attachBody = webClient.DownloadData(attachmentUrl); attach = new activitymimeattachment(); attach.attachmentnumber = new CrmNumber(); attach.attachmentnumber.Value = i; attach.activityid = new Lookup(); attach.activityid.type = EntityName.email.ToString(); attach.activityid.Value = emailId; attach.body = System.Convert.ToBase64String(attachBody); attach.subject = entity.title; attach.filename = entity.filename; attach.mimetype = entity.mimetype; Guid attachId = service.Create(attach); Console.WriteLine("attachId=" + attachId.ToString()); } } SendEmailRequest sendEmailReq = new SendEmailRequest(); sendEmailReq.EmailId = emailId; sendEmailReq.TrackingToken = " "; sendEmailReq.IssueSend = true; SendEmailResponse sendEmailRes = (SendEmailResponse)service.Execute(sendEmailReq); } | 
|  | 
| Теги | 
| email, workflow, crm3 | 
|  | 
| 
 |