Thursday, September 13, 2012

Role-based Security vs Object-based Security


Role-based security in Microsoft Dynamics CRM focuses on grouping a set of privileges together that describe the tasks that are performed for a user in a specific job function. The basic concepts of role-based security include the following:

  • Users are assigned one or more roles based on their job function or tasks
  • Roles are associated with permissions (privileges and access levels) for the different business objects (entities)
  • Users gain access to entities or groups of entities in the system via membership in a role that has been assigned the necessary privileges and access levels to perform the users’ jobs.

Object-based security in Microsoft Dynamics CRM focuses on how users gain access to individual instances of business objects (entities).

Role-based Security
Role-based security in Microsoft Dynamics CRM is based on the interaction of privileges and access levels, which work together through the use of security roles.
Privileges define what actions a user can perform on each entity in Microsoft Dynamics CRM. Privileges are pre-defined in Microsoft Dynamics CRM and cannot be changed; examples of privileges include Create, Read, Write, and Delete.
Access levels indicate which records associated with each entity the user can perform actions upon.The access level associated with a privilege determines (for a given entity type) the levels within the organizational hierarchy (User, team and Business Unit) at which a user belonging to a specific role can act on that type of entity.
Each security role provides a combination of privileges and access levels specific to a Microsoft Dynamics CRM job function.

Object-based Security
Object-based security applies to individual instances of entities and is provided by using access rights. An access right is granted to a user for a particular entity instance.
The relationship between an access right and a privilege is that access rights apply only after privileges have taken effect. For example, if users do not have the privilege to read accounts, they will be unable to read any account, regardless of the access rights another user might grant them to a specific account through sharing.

Auto Numbering in MS CRM


we can achieve the auto numbering solution in multiple ways few are below
Option 1:Very simple, supported and mostly acceptable way of auto numbering is to read the attribute Max value and then add 1 to get next auto number. For example you have a custom entity named Project and you want to auto number Project_Ref_Number attribute. But do not retrieve all records. Just retrieve the record with maximum number value by using following two properties of PageInfo Class in SDK and set descending order.
PageInfo.Count = 1;
PageInfo.PageNumber = 1;
One more consideration should be taken in account to register your auto number plugin to at PreCreate rather at PostCreate.
Issues:In multi-user environment, this approach can come up with duplicate numbers in Project_Ref_Number when more than one user is creating project records.
Option 2:This technique requires a bit more work but still supported way of doing things and all the time you will be getting 100% unique number.
You need to create a new table for project entity in a different database and not in CRM default database.
create table dbo.ProjectNumbers
(
 Project_Ref_Number int identity(1,1) primary key clustered,
 Projectid uniqueidentifier not null
)
go
Create a stored procedure for inserting a record into new database. This will increase the performance of your insert query.
create procedure dbo.proc_new_ProjectNumber
@ProjectId uniqueidentifier,
@Project_Ref_Number int output
as
insert into dbo.ProjectNumber
(
 ProjectId
)
values
(
 @ProjectId
)
select @Project_Ref_Number = scope_identity()
go
In your Plugin/Callout:
1.   Access you database using ADO.NET
2.   Execute stored procedure and get next number from returned results
3.   Set the value of the returned number to target entity attribute approperiatly.
4.   All Done
Issues:
1.   You have to setup database.
2.   You have to read and insert into external database.
Option 3:
This option used a lock mechanism on a text file placed somewhere at your webserver. You can create one file to store next number for all entities or you can create one file for each entity. In your Plugin/Callout:
1.   Put a lock on file.
2.   Read the file and read the number there.
3.   Update the number by adding 1.
4.   Release the lock.
5.   Use this number and set your target entity attribute appropriately.

string ProjectAutoNumber = “FilePath”
lock(this)
{                            
TextReader textReader = File.OpenText(ProjectAutoNumber);
AutoNumber = textReader.ReadLine();
textReader.Close();
AutoNumber = (long.Parse(AutoNumber) + 1).ToString();
TextWriter textWriter = File.CreateText(ProjectAutoNumber);
textWriter.WriteLine(AutoNumber);
textWriter.Close();
}
Issues:
1.   Resource locking
2.   File system Read/write cost
all these options works well but still I am looking for some more robust solution.GUID’s are instantly available and 100% unique.
NOTE: you can use the auto numbering using the dates also.



Retrieve more than 10000 records from Export to Excel in MS CRM


update [CRM_MSCRM].[dbo].[OrganizationBase] SET [MaxRecordsForExportToExcel] = 300000 where NAME ='CRM'

Second Approach:-
We can create a report with the same query used in Advanced Find and run the report here you can get all the records with option Export to Excel.

Wednesday, September 12, 2012

Generate the plugin registration.exe and device registration.exe for crm 2011 from sdk


First build[Microsoft Visual Studio 2010] the plugin registration folder file from crm sdk
then it will show the bin--> debug folder with exe file

Second  build[Microsoft Visual Studio 2010] the Device registration folder file from crm sdk
then it will show the bin--> debug folder with exe file

then goto cmd-> goto that folder[Device Registratiom.exe] type the below command

E:\sdk\tools>cd deviceregistration

E:\sdk\tools\deviceregistration>cd bin

E:\sdk\tools\deviceregistration\bin>cd debug

E:\sdk\tools\deviceregistration\bin\Debug>deviceregistration.exe /operation:register
Error: Device is already registered.
Device ID: ----------------------
Device Password: -----------------------

It will generate the Device ID and Password as above.
open the command prompt once again go to bin folder in sdk

E:\sdk\bin>crmsvcutil.exe /url:https://demo1.api.crm5.dynamics.com/XRMServices/2011/Organization.svc /o:demo1.cs /n:demo1namespace /u:"emailid" /p:"password" /di: DeviceID /dp: DevicePassword /serviceContextName:demo1context

For OnPremise

E:\sdk\bin>CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /out:CRM2011VM.cs /url:http://test:5555/CRM2011VM/XRMServices/2011/Organization.svc /domain:CRM2011VM /username:administrator /password:p@ssword /namespace:Xrm /serviceContextName:XrmServiceContext

Tuesday, September 11, 2012

Error while importing the managed solution


A managed solution cannot overwrite the SavedQuery component with Id=xxxx-xxx-xxx-xxx-xxxx  which has an unmanaged base instance.The most likely scenario for this error is that an unmanaged solution has installed a new unmanaged SavedQuery component on the target system, and now a managed solution from the same publisher is trying to install that same SavedQuery component as managed. This will cause an invalid layering of solutions on the target system and is not allowed.

If yes, you need to remove Activity feed configuration from source system before exporting your solution. You need to follow below steps
1. Open your Dev envornment.
2. Navigate to Activity Feeds Configuration under Setting->System.
3. Delete all configuration records except for user entity.
4. Delete user entity record.

 Now you can export your solution, make sure to click on “Publish All Customization” during export step.
Once solution imported into production envirnment, you can configure activity feed again.

Display Date from datetime in MS CRM


Write the below script in onchange of date field

var m_names = new Array("January", "February", "March", 

"April", "May", "June", "July", "August", "September", 
"October", "November", "December"); 
var d = new Date(); 
var curr_date = d.getDate(); 
var curr_month = d.getMonth(); 
var curr_year = d.getFullYear(); 
alert(curr_date+"-"+m_names[curr_month] +"-"+ "-" + curr_year);