MSCRM 2011, 2013, 2015, 2016, C#, Dynamics 365 CE, ASP.net and MVC, Azure, Power Platform
Saturday, 31 October 2015
Code to check if the user is a team member in CRM 2011/2013/2015
Hi,
Today we got a requirement to check if the user is a member of particular team and do some operation based on that.
Here is the C# code to check the user is a team member of the team.
public static bool CheckTeamMember(Guid guidTeam, Guid guidUser, IOrganizationService iService)
{
QueryExpression objQueryExp = new QueryExpression("team");
objQueryExp.ColumnSet = new ColumnSet(true);
objQueryExp.Criteria.AddCondition(new ConditionExpression("teamid", ConditionOperator.Equal, guidTeam));
LinkEntity lnkEntity = objQueryExp.AddLink("teammembership", "teamid", "teamid");
lnkEntity.LinkCriteria.AddCondition(new ConditionExpression("systemuserid", ConditionOperator.Equal, guidUser));
EntityCollection entColResults = iService.RetrieveMultiple(objQueryExp);
if (entColResults.Entities.Count > 0)
{
return true;
}
else
{
return false;
}
}
Hope this helps.
--
Happy CRM'ing
Gopinath
Today we got a requirement to check if the user is a member of particular team and do some operation based on that.
Here is the C# code to check the user is a team member of the team.
public static bool CheckTeamMember(Guid guidTeam, Guid guidUser, IOrganizationService iService)
{
QueryExpression objQueryExp = new QueryExpression("team");
objQueryExp.ColumnSet = new ColumnSet(true);
objQueryExp.Criteria.AddCondition(new ConditionExpression("teamid", ConditionOperator.Equal, guidTeam));
LinkEntity lnkEntity = objQueryExp.AddLink("teammembership", "teamid", "teamid");
lnkEntity.LinkCriteria.AddCondition(new ConditionExpression("systemuserid", ConditionOperator.Equal, guidUser));
EntityCollection entColResults = iService.RetrieveMultiple(objQueryExp);
if (entColResults.Entities.Count > 0)
{
return true;
}
else
{
return false;
}
}
Hope this helps.
--
Happy CRM'ing
Gopinath
Basic functions of Master, MSDB, Model and Tempdb databases in SQL Server
After a long time, I did open SQL Server Management Studio and connected to a database. Just remembered the basis which I read when I didn't my career.
Master
This database holds information for all databases located on the SQL Server instance and is the glue that holds the engine together. Because SQL Server cannot start without a functioning master database, you must administer this database with care.
Msdb
This database stores information regarding database backups, SQL Agent information, DTS packages, SQL Server jobs, and some replication information such as for log shipping.
Model
This database is essentially a template database used in the creation of any new user database created in the instance.
Tempdb
The tempdb holds temporary objects such as global and local temporary tables and stored procedures.
Hope this helps.
--
Cheers,
Gopinath
Master
This database holds information for all databases located on the SQL Server instance and is the glue that holds the engine together. Because SQL Server cannot start without a functioning master database, you must administer this database with care.
Msdb
This database stores information regarding database backups, SQL Agent information, DTS packages, SQL Server jobs, and some replication information such as for log shipping.
Model
This database is essentially a template database used in the creation of any new user database created in the instance.
Tempdb
The tempdb holds temporary objects such as global and local temporary tables and stored procedures.
Hope this helps.
--
Cheers,
Gopinath
Thursday, 29 October 2015
Set Due Date by Considering Working Days in CRM
Hi,
Today we got a requirement to create a task where the due date of it next 2 working days from today.
Immediately, our minds thought very complex logic of having a custom entity and storing values etc to find working days logic..
After some search, we have designed a simple approach for it by using OOB Business closures Calendar.
Here is the procedure for it.
1) Go to Settings-> Business Closures
2) Create your holiday list here
3) Use the following code for getting date by considering the working days as a parameter.
// Get business closure calendar
QueryExpression calenderQuery = new QueryExpression
{
EntityName = "calendar",
ColumnSet = new ColumnSet(true),
Criteria =
{
Conditions =
{
new ConditionExpression("name", ConditionOperator.Equal, "Business Closure Calendar")
}
}
};
EntityCollection businessClosureCalender = iService.RetrieveMultiple(calenderQuery);
// Advance start date by 1 day until required number of working days have been added
DateTime requiredDate = DateTime.Now;
// int daysToAdd = 3;
while (intDaysToAdd > 0)
{
requiredDate = requiredDate.AddDays(1);
if (isWorkingDay(businessClosureCalender, requiredDate)) intDaysToAdd--;
}
return requiredDate;
}
// Check whether a date/time is a working day or not
public static bool isWorkingDay(EntityCollection businessClosureCalender, DateTime time)
{
// Check if date/time is a Saturday or Sunday
if (time.DayOfWeek == DayOfWeek.Saturday || time.DayOfWeek == DayOfWeek.Sunday)
{
// Weekend = non-working day
return false;
}
// Check if date/time falls within a Business Closure period
if (businessClosureCalender.Entities.Count > 0)
{
EntityCollection businessClosureRules = (EntityCollection)businessClosureCalender.Entities[0].Attributes["calendarrules"];
foreach (Entity rule in businessClosureRules.Entities)
{
if ((DateTime)rule.Attributes["effectiveintervalstart"] <= time && (DateTime)rule.Attributes["effectiveintervalend"] > time)
{
// Business closure= non-working day
return false;
}
}
}
// Date/Time is not a weekend or within a business closure period, so it is a working day
return true;
}
Hope this helps.
--
Happy CRM'ing
Gopinath
Today we got a requirement to create a task where the due date of it next 2 working days from today.
Immediately, our minds thought very complex logic of having a custom entity and storing values etc to find working days logic..
After some search, we have designed a simple approach for it by using OOB Business closures Calendar.
Here is the procedure for it.
1) Go to Settings-> Business Closures
2) Create your holiday list here
3) Use the following code for getting date by considering the working days as a parameter.
public static DateTime GetDatePlusWorkingDays(IOrganizationService iService, int intDaysToAdd)
{// Get business closure calendar
QueryExpression calenderQuery = new QueryExpression
{
EntityName = "calendar",
ColumnSet = new ColumnSet(true),
Criteria =
{
Conditions =
{
new ConditionExpression("name", ConditionOperator.Equal, "Business Closure Calendar")
}
}
};
EntityCollection businessClosureCalender = iService.RetrieveMultiple(calenderQuery);
// Advance start date by 1 day until required number of working days have been added
DateTime requiredDate = DateTime.Now;
// int daysToAdd = 3;
while (intDaysToAdd > 0)
{
requiredDate = requiredDate.AddDays(1);
if (isWorkingDay(businessClosureCalender, requiredDate)) intDaysToAdd--;
}
return requiredDate;
}
// Check whether a date/time is a working day or not
public static bool isWorkingDay(EntityCollection businessClosureCalender, DateTime time)
{
// Check if date/time is a Saturday or Sunday
if (time.DayOfWeek == DayOfWeek.Saturday || time.DayOfWeek == DayOfWeek.Sunday)
{
// Weekend = non-working day
return false;
}
// Check if date/time falls within a Business Closure period
if (businessClosureCalender.Entities.Count > 0)
{
EntityCollection businessClosureRules = (EntityCollection)businessClosureCalender.Entities[0].Attributes["calendarrules"];
foreach (Entity rule in businessClosureRules.Entities)
{
if ((DateTime)rule.Attributes["effectiveintervalstart"] <= time && (DateTime)rule.Attributes["effectiveintervalend"] > time)
{
// Business closure= non-working day
return false;
}
}
}
// Date/Time is not a weekend or within a business closure period, so it is a working day
return true;
}
Hope this helps.
--
Happy CRM'ing
Gopinath
Tuesday, 27 October 2015
Remove Border on the Form for the WebResource
Hi,
Today we got requirement to add a button on the form for some custom validation.
For that, we have created a HTML Web resource with a button and add it on the form.
Unfortunately, we saw a border on form.
We struggled for some time to remove it and came to know that it was a simple check box to uncheck.
1) Go to Web Resource properties
2) Click on Formatting tab.
3) Scroll down, you will an option for disabling border.
Now, you won't see a border on the form.
Hope this helps.
--
Happy CRM'ing
Gopinath
Today we got requirement to add a button on the form for some custom validation.
For that, we have created a HTML Web resource with a button and add it on the form.
Unfortunately, we saw a border on form.
We struggled for some time to remove it and came to know that it was a simple check box to uncheck.
1) Go to Web Resource properties
2) Click on Formatting tab.
3) Scroll down, you will an option for disabling border.
Now, you won't see a border on the form.
Hope this helps.
--
Happy CRM'ing
Gopinath
Wednesday, 21 October 2015
Get the current entity name and id using javascript in CRM 2011/2013/2015
Hi,
This might be known for every one who has experience of Level 100 on MS CRM but this might be helpful when we need the correct syntax quickly.
Use the following lines to get the entity name and id of record in CRM 2011/2013/2015
Xrm.Page.data.entity.getEntityName()
Xrm.Page.data.entity.getId()
Hope this helps.
--
Happy CRM'ing
Gopinath
This might be known for every one who has experience of Level 100 on MS CRM but this might be helpful when we need the correct syntax quickly.
Use the following lines to get the entity name and id of record in CRM 2011/2013/2015
Xrm.Page.data.entity.getEntityName()
Xrm.Page.data.entity.getId()
Hope this helps.
--
Happy CRM'ing
Gopinath
Tuesday, 20 October 2015
Add a button in CRM 2013/2015 using Ribbonworkbench
Most of the times we get a requirement to add a button on the CRM OOB forms for full filling business needs.
Here are the steps for adding a button
1) Download Ribbon Work Bench solution from the following linkDownload Ribbon WorkBench
2) Import the solution to CRM.
3) Create a solution with the entities and web resources where you wanted to add a button. In my case, its on Opportunity.
4) Go to CRM-> Settings->Solutions.
5) You will see a link with name "RIBBON WORKBENCH" as shown in the below screen shot.
6) click on link and it will open a pop-up to select the solution to open.
7) The workbench all the information related to the entities from the solution.
8) Click on Ribbon tab button as shown in the figure.
9) You will see a dropdown on the top right side window for selection place to show the ribbon button. In my case, I would like add a button on the Opportunity Form.
10) Drag the button from left and release it in the place where you wanted to create a button.
11) Select the button and give the details like label, description, Image etc..
12) Select Commands and click on Add New
13) It will create a command for you. Expand Command and right click on the command. It will display you to select Display Rules, Actions and Enable Rules.
14) Select Actions and it will open a pop-up.
15) Click on Add button, it will open a pop-up to select a JavaScript function or a URL. If you want to open and HTML web resource or any URL, you can just give the URL by selecting the Open URL Action. If you want trigger any JavaScript method on the click of the button, select JavaScript Function Action.
16) Click on JavaScript Action and give Function Name which you wanted to trigger on the button click, web resource name and parameters if any.
17) Expand Buttons and select the button which was created.
18) Click on Command dropdown as shown in the screen shot. You will see the command which you have created, select that and click on Publish button on the top.
19) Click on Publish button.
Here is the output.
Hope this helps.
--
Happy CRM'ing
Here are the steps for adding a button
2) Import the solution to CRM.
3) Create a solution with the entities and web resources where you wanted to add a button. In my case, its on Opportunity.
4) Go to CRM-> Settings->Solutions.
5) You will see a link with name "RIBBON WORKBENCH" as shown in the below screen shot.
6) click on link and it will open a pop-up to select the solution to open.
7) The workbench all the information related to the entities from the solution.
8) Click on Ribbon tab button as shown in the figure.
9) You will see a dropdown on the top right side window for selection place to show the ribbon button. In my case, I would like add a button on the Opportunity Form.
11) Select the button and give the details like label, description, Image etc..
12) Select Commands and click on Add New
13) It will create a command for you. Expand Command and right click on the command. It will display you to select Display Rules, Actions and Enable Rules.
14) Select Actions and it will open a pop-up.
15) Click on Add button, it will open a pop-up to select a JavaScript function or a URL. If you want to open and HTML web resource or any URL, you can just give the URL by selecting the Open URL Action. If you want trigger any JavaScript method on the click of the button, select JavaScript Function Action.
17) Expand Buttons and select the button which was created.
18) Click on Command dropdown as shown in the screen shot. You will see the command which you have created, select that and click on Publish button on the top.
19) Click on Publish button.
Here is the output.
Hope this helps.
--
Happy CRM'ing
Gopinath
Est. Revenue on Opportunity in CRM 2011/2013/2015
Today I was working on the Opportunity and checking OOB fields to reuse. Then I see that Est. Revenue field is disable and it has the same value of Total Amount field.
After some search, I came to know that Est. Revenue is disabled/enabled based on Revenue Option set (User Provided, System Calculated)
System Calculated
Est. Revenue = Total Amount (Sum of the products added to opportunity)
Read Only = Yes
User Provided
Est. Revenue = User defined value.
Read Only = No
It means even though the total amount is $ 100, the sales person can go ahead and get the deal for $ 150 which is User Provided Est. Revenue.
Hope this helps.
--
Happy CRM'ing
Gopinath
After some search, I came to know that Est. Revenue is disabled/enabled based on Revenue Option set (User Provided, System Calculated)
System Calculated
Est. Revenue = Total Amount (Sum of the products added to opportunity)
Read Only = Yes
User Provided
Est. Revenue = User defined value.
Read Only = No
It means even though the total amount is $ 100, the sales person can go ahead and get the deal for $ 150 which is User Provided Est. Revenue.
Hope this helps.
--
Happy CRM'ing
Gopinath
Monday, 19 October 2015
The object type cannot be added to a queue in CRM 2013/2015
Hi,
Today, I was working on the requirement where I should create a task and add to the queue. As it can be easily done using workflow I have created a workflow and added the below steps.
But unfortunately, when I ran got an error saying
"The record specified cannot be added to a queue. This record type is not enable for use in queues."
and in the details section it was logged an error with the below message
"The object type cannot be added to a queue"
I did check for task entity the Queues are enabled by default OOB and able to a task record to the queue by clicking on Add to Queue button.
After some search I found the work around for the issue is we should enable the queues on the entity on which the workflow is configured. Even though it looks meaning less for now as we don't an option we should follow it.
Hope this helps.
--
Happy CRM'ing
Gopinath
Today, I was working on the requirement where I should create a task and add to the queue. As it can be easily done using workflow I have created a workflow and added the below steps.
But unfortunately, when I ran got an error saying
"The record specified cannot be added to a queue. This record type is not enable for use in queues."
and in the details section it was logged an error with the below message
"The object type cannot be added to a queue"
I did check for task entity the Queues are enabled by default OOB and able to a task record to the queue by clicking on Add to Queue button.
After some search I found the work around for the issue is we should enable the queues on the entity on which the workflow is configured. Even though it looks meaning less for now as we don't an option we should follow it.
Hope this helps.
--
Happy CRM'ing
Gopinath
Sunday, 18 October 2015
CRM 2015-2013 Cortana Commands
Hi,
I was exploring new features of Windows 10. We all know that Cortana is power full feature of Windows 10.
Here are the Cortana Commands for CRM.
The create commands work only with Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update. The other commands work with Microsoft Dynamics CRM 2013 and Microsoft Dynamics CRM Online as well as Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update.
Hope this helps.
--
Happy CRM'ing
Gopinath
I was exploring new features of Windows 10. We all know that Cortana is power full feature of Windows 10.
Here are the Cortana Commands for CRM.
To
do this in CRM
|
Say
this
|
Open an item
|
CRM open <item>
called <item name>.
Example:
“CRM open account called Contoso.”
Variation:
“CRM open account named
Contoso.”
|
Show a view
|
CRM show <view name>.
Example:
“CRM show my active accounts.”
Variation:
“CRM show me my active accounts.”
|
Search for an item
|
CRM find <item>
called <name>.
Example:
“CRM find account called Contoso.”
Variation:
“CRM find account named
Contoso.”
|
Create a new item
|
CRM create <item type> called <item
name>.
Example:
“CRM create contact called Maria Campbell.”
Variation:
“CRM add new contact named Maria Campbell.”
|
Create a phone call activity
|
CRM remind me to call <call
name>.
Example:
“CRM remind me to call Maria
Campbell to set up appointment.”
|
Create an appointment
|
CRM schedule meeting to <subject>.
Example:
“CRM schedule meeting to discuss quote with Maria
Campbell.”
|
Create a task
|
CRM remind me to <task
name>.
Example:
“CRM remind me to email Maria
Campbell.”
Variations:
“CRM follow up Maria
Campbell.”
“CRM follow up with Maria
Campbell.”
“CRM follow up on Contoso.”
|
Open task list
|
CRM what should I do next?
Example:
|
The create commands work only with Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update. The other commands work with Microsoft Dynamics CRM 2013 and Microsoft Dynamics CRM Online as well as Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update.
Hope this helps.
--
Happy CRM'ing
Gopinath
Subscribe to:
Posts (Atom)