Export emal template from CRM4 to CRM 2016 - dynamics-crm

I need to export email templates from CRM 4 directly into CRM 2016. Can't go over the complete upgrade process so my best guess would be to export using services, connect to CRM 4 and then import into CRM 2016. The problem seems to be the import into CRM 2016 which throws a faultexception. But before I would start looking into to this I tried to recreate a template that I created in CRM 2016. Using the services but this also doesn't seem so easy to do..the process creates a copy of the email template but subject and body are missing. Does this need to be casted to something esle? What could be the problem here?
This is the code I used:
ColumnSet cols = new ColumnSet(new string[] { Template.AttributeLogicalNames.Title, Template.AttributeLogicalNames.Subject,
Template.AttributeLogicalNames.TemplateTypeCode, Template.AttributeLogicalNames.IsPersonal,
Template.AttributeLogicalNames.LanguageCode, Template.AttributeLogicalNames.Body });
QueryExpression query = new QueryExpression(Template.EntityLogicalName);
query.ColumnSet = cols;
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("title", ConditionOperator.Equal, "TestTemplate Candidate");
EntityCollection results = _service.RetrieveMultiple(query);
foreach (var item in results.Entities)
{
Template template = new Template() { Title = ((Template)item).Title + "-2", Subject = ((Template)item).Subject,
TemplateTypeCode = ((Template)item).TemplateTypeCode, IsPersonal = ((Template)item).IsPersonal,
LanguageCode = ((Template)item).LanguageCode,Body = ((Template)item).Body
};
Guid templateid = _service.Create(template);
Console.WriteLine("Template created with Guid: {0}", templateid);
}

It seems I was missing some fields: subjectpresentationxml, presentationxml, generatetypecode

Related

Is there a way to view LINQ Generated query expressions in CRM Dynamics?

Considering the fact LINQ queries in CRM Dynamics are translated into query expressions (source):
[...] The OrganizationServiceContext class contains an underlying LINQ
query provider that translates LINQ queries from Microsoft Visual C#
or Microsoft Visual Basic .NET syntax into the query API used by
Microsoft Dynamics CRM. [...]
Is there a way to see the generated query expressions (As it's possible to see the generated SQL query in Linq-to-Sql or Linq-to-Entities)?
You can use reflection to get the query object and then convert that to a FetchXML query to get a printable query. This will work with both early-bound and late-bound queries.
From: https://pogo69.wordpress.com/2012/04/05/crm-linq-provider-converting-expressions-to-queryexpression-andor-fetchxml/
var connectionString = #"SET YOUR CONNECTION STRING";
var service = new CrmServiceClient(connectionString);
using (var xrm = service.OrganizationServiceProxy)
{
OrganizationServiceContext orgContext =
new OrganizationServiceContext(xrm);
var query = from c in orgContext.CreateQuery("contact")
join a in orgContext.CreateQuery("account")
on c["contactid"] equals a["primarycontactid"]
where (String)c["lastname"] == "Wilcox" ||
(String)c["lastname"] == "Andrews"
where ((String)a["address1_telephone1"]).Contains("(206)")
|| ((String)a["address1_telephone1"]).Contains("(425)")
select new
{
Contact = new
{
FirstName = c["firstname"],
LastName = c["lastname"]
},
Account = new
{
Address1_Telephone1 = a["address1_telephone1"]
}
};
IQueryProvider queryProvider = query.Provider;
MethodInfo translateMethodInfo = queryProvider.GetType().GetMethod("Translate");
QueryExpression queryEx = (QueryExpression)translateMethodInfo.Invoke(queryProvider, new object[] { query.Expression });
QueryExpressionToFetchXmlRequest reqConvertToFetchXml = new QueryExpressionToFetchXmlRequest { Query = queryEx };
QueryExpressionToFetchXmlResponse respConvertToFetchXml = (QueryExpressionToFetchXmlResponse)xrm.Execute(reqConvertToFetchXml);
Console.WriteLine("To FetchXML:" + Environment.NewLine + Environment.NewLine);
Console.WriteLine(respConvertToFetchXml.FetchXml);
Alternatively you could use Fiddler to capture the actual query text sent in the SOAP message. I've done this before and haven't found it any more valuable than the FetchXml.

Work Item Linked Queries/Scripts for Reporting in Visual Studio Team Services (VSTS)

I wanted to create a report on my VSTS Team Project which has the details of the Work Item Linking relationships in a Team Project. Ex: Epics→Features→UserStories. Since there are parent/child relationships between Epics & Features and also between Features & UserStories, I wanted to create a report (.csv or .xls) which has all the details of these workitems and their relationships.
Could someone let me know on what is the best and easy way to achieve this?
I suggest that you could check it via project with TFS add-in (included in VS or team explorer).
Create a query (Tree of work items)
Open Project
Click Team=>Choose Team project
Click Get Work Items=>Select that query=>Find=>Select All=>OK
After that you can check the result in project, you also can collapse parent item by clicking corresponding title.
You can achieve it programmatically by using TFS API with Excel add-in.
Create a document level excel add-in project
Install Microsoft Team Foundation Server Extended Client package
Run query by using Query.RunLinkQuery method.
Get test cases in requirement test suites
Check test results of these test cases
Get associated work item of test result
Save data to excel per your detail requirement.
Simple code:
var credentials = new NetworkCredential("[user name]", "[password]");
TfsTeamProjectCollection tfsCollection = new TfsTeamProjectCollection(new Uri("https://XX.visualstudio.com"));
ITestManagementService tms = tfsCollection.GetService<ITestManagementService>();
ITestManagementTeamProject teamProject = tms.GetTeamProject("[team project name]");
WorkItemStore workitemstore = tfsCollection.GetService<WorkItemStore>();
QueryHierarchy queryRoot = workitemstore.Projects["[team project name]"].QueryHierarchy;
QueryFolder queryFolder = queryRoot["Shared Queries"] as QueryFolder;
QueryDefinition qd = queryFolder["[query name]"] as QueryDefinition;
Dictionary<string, string> variables = new Dictionary<string, string>();
variables.Add("project", "[team project name]");
Query query = new Query(workitemstore, qd.QueryText, variables);
var results = query.RunLinkQuery();
foreach(var lr in results)
{
//check relationship according to sourceId, TargetId and LinkTypeId (2: child)
int parentId = lr.SourceId;
int currentId = lr.TargetId;
}
foreach (ITestPlan p in teamProject.TestPlans.Query("Select * From TestPlan"))
{
Console.WriteLine("Plan - {0} : {1}", p.Id, p.Name);
foreach (var suite in p.RootSuite.SubSuites)
{
IRequirementTestSuite requirementSuite = suite as IRequirementTestSuite;
if (requirementSuite != null)
{
var requirementId = requirementSuite.RequirementId;
//check requirementId with user story Id
foreach(var tc in requirementSuite.TestCases)
{
var lastResult = teamProject.TestResults.ByTestId(tc.Id).OrderByDescending(tr => tr.DateStarted).FirstOrDefault();
if(lastResult.Outcome== Microsoft.TeamFoundation.TestManagement.Client.TestOutcome.Failed)
{
int[] ids= lastResult.QueryAssociatedWorkItems();
foreach(int id in ids)
{
var wit = workitemstore.GetWorkItem(id);
}
}
}
}
}
}

Is Dynamics CRM 2013 sdk cache result of QueryExpresions by Default?

I wrote this simple query:
var connectionString = String.Format("Url={0}; Username={1}; Password={2}; Domain={3}", url, username, password, domain);
var myConnection = CrmConnection.Parse(connectionString);
CrmOrganizationServiceContext _service = new CrmOrganizationServiceContext(myConnection);
var whoAmI = _service.Execute(new WhoAmIRequest());
var query = new QueryExpression
{
EntityName = "phonecall",
ColumnSet = new ColumnSet(true)
};
query.PageInfo = new PagingInfo
{
Count = 20,
PageNumber = 1,
PagingCookie = null
};
query.Orders.Add(new OrderExpression
{
AttributeName = "actualstart",
OrderType = OrderType.Descending
});
query.Criteria = new FilterExpression() { FilterOperator = LogicalOperator.And };
query.Criteria.AddCondition("call_caller", ConditionOperator.In, lines);
var entities = _service.RetrieveMultiple(query).Entities;
I have a program which runs this query every minute. On the first execution the correct results are displayed but for subsequent queries the results never change as I update records in CRM.
If I restart my program the results refresh correctly again on the first load.
Why are the results not updating as records are modified in CRM?
It is the CrmOrganizationServiceContext that is doing the caching - I found the following worked a treat and the results of my RetrieveMultiple are no longer cached :)
Context = new CrmOrganizationServiceContext(CrmConnection.Parse(connectionString));
Context.TryAccessCache(cache => cache.Mode = OrganizationServiceCacheMode.Disabled);
RetrieveMultiple always brings back fresh results so there must be some other aspect of your program which is causing stale data to be displayed.

How to query Opportunities in Microsoft Dynamics CRM 2011

I am trying to query Opportunity information from Microsoft Dynamincs CRM 2011.
Any idea why I keep getting a 401 Unauthorized error?
If I use the URL in the browser it seems to work.
Uri organizationUri = new Uri("/XRMServices/2011/OrganizationData.svc");
Uri homeRealmUri = null;
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain");
OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
// Get the IOrganizationService
IOrganizationService orgService = (IOrganizationService)orgProxy;
//Get OrganizationServiceContext -the organization service context class implements the IQueryable interface and
//a .NET Language-Integrated Query (LINQ) query provider so we can write LINQ queries against Microsoft Dynamics CRM data.
OrganizationServiceContext orgServiceContext = new OrganizationServiceContext(orgService);
// Get name,number and ownerid for all the account records
var queryAccount1 = from r in orgServiceContext.CreateQuery("opportunity")
select new
{
CustomerID = r["customerid"],
};
foreach (var account in queryAccount1)
{
txtCustomerID.Text = account.CustomerID.ToString();
}
Are you accessing you CRM on the intranet or IFD? I think the problem is the way you set up credentials.
Setting up NetworkCredential class will not work if you are accessing your CRM through IFD
var credentials = new ClientCredentials();
credentials.UserName.UserName = "username";
credentials.UserName.Password = "password";
var organizationUri = new Uri("https://externaluri");
var organizationServiceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null);
organizationServiceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

How can I update the record in sharepoint 2010 using linq

I am unable to update the record in SharePoint 2010 using new linq feature.
follwoing in my code please review it.
AbsentTrackingSystemEntitiesDataContext ctx = new AbsentTrackingSystemEntitiesDataContext(spWeb.Url);
ctx.ObjectTrackingEnabled = true;
HolidaysItem Holidayobj = GetHolidays(HolidayID, ctx); // get the specific record to be update.
if (Holidayobj != null)
{
Holidayobj.Title = "test";
Holidayobj.HolidayDate = DateTime.Today;
Holidayobj.Description = "test holiday";
ctx.Holidays.Attach(Holidayobj);
// or ctx.Holidays.Attach(Holidayobj, true); not working in 2010
ctx.SubmitChanges();
}
This is not required at all.
ctx.Holidays.Attach(Holidayobj);
ctx.SubmitChanges(); is all you need

Resources