Wednesday, August 28, 2013

Difference between logged in user id and system user id in crm 2011

Question-
I am using  WhoAmIRequest Class to get user id but when i use the same user  id to return output as a lookup in Custom workflow and set To field  in Email entity i get error. If i compare this id with the guid of user in mscrm 2011 then i find it's different. what exactly i get from who am i request.

Answer -
The "WhoAmIRequest" returns the Id of the user that is running the current process. Automatic workflows run under the user context of the workflow owner and not under the context of the currently logged in user. This is probably why you are getting different values for the User Id.

Workflows that run on demand (a user initiates a workflow via the ribbon button) run under the context of the current logged in user. Maybe this is what you actually need.

Thursday, April 18, 2013

Error Handling in MSCRM 2011 Javascript




 
In addition to these error types, catching default syntax errors can be done by using the
standard
onerror event of the window. The syntax for that is as follows:
window.onerror = function(parameters){
// processing
}
Add this to the script section of the head.
To handle unexpected processing, perform the following steps:
1. Open the
Contact entity's main form for editing.
2. Add a new option set named
Errors (new_errors), with options such as URIError,
RangeError
, ReferenceError, EvalError, TypeError, SyntaxError, and
CustomError
.
3.
Add the field to your form.
4. Save and publish the form.
5. Create a new JScript web resource in your solution. Name it
JS Errors
(
new_jserrors).
6. Add the following function to your resource:
function ErrorHandler()
{
var _error = Xrm.Page.getAttribute("new_errors").
getSelectedOption().text;
// alert("Selected option is: " + _error);
switch(_error)
{
case "URIError":
try
{
decodeURIComponent("%");
}
catch(err)
{


alert(err.name + " || " + err.message);
}
break;
case "RangeError":
var _age = 120;
try
{
if(_age > 100)
{
throw new RangeError("Age cannot be over 100");
}
}
catch(err)
{
alert(err.name + " || " + err.message);
}
break;
case "ReferenceError":
try
{
// use an undeclared variable
trying.thisone;
// TypeError due to browser
}
catch(err)
{
alert(err.name + " || " + err.message);
}
break;
case "EvalError":
// not used in recent versions, but supported
try
{
var y = new eval();
// TypeError due to browser
}
catch(err)
{
alert(err.name + " || " + err.message);
}
break;
case "TypeError":
try


{
var _obj = {};
// call undefined method
_obj.execute();
}
catch(err)
{
alert(err.name + " || " + err.message);
}
break;
case "SyntaxError":
try
{
var _x = "some string";
var _y = 10;
var _total = eval(_x + _y);
}
catch(err)
{
alert(err.name + " || " + err.message);
}
break;
case "CustomError":
try
{
throw new Error("Custom Error message");
}
catch(err)
{
alert(err.name + " || " + err.message);
}
break;
default:
// do nothing
}
}
7. Associate the
ErrorHandler function to the OnChange event of the field we
created.
8. Save and publish your solution.
9. Test the function by changing the values in the option set.
 



 

Sechedule Service Activity in MSCRM 2011



 
The diagram in this article illustrates how you can schedule a service activity in Microsoft Dynamics CRM. A service activity is an appointment to provide a service to a customer. It uses one or more resources to perform a service at a specific time.
  • Initiate - A customer calls to make an appointment.
  • Request - The scheduler creates a service activity, selects a service that the customer wants, and then searches for availability within a time frame, such as “This Week.”
  • Search - Microsoft Dynamics CRM uses the selection rule to search for available times in the work schedules of the resources that can perform the service.
  • Reserve - The scheduler discusses the choices with the customer, who chooses one.
      



Automated Service Scheduling works the way you work

Microsoft CRM  includes an appointment-based service scheduling capability that enables you to define your services, resources, work schedules, and service locations. A sophisticated scheduling engine manages appointment booking and service availability according to your business rules. You can adjust it to optimize scheduling and reduce resource usage and costs. Point-and-click reports help service managers identify trends and adjust services and resources to meet demand. And because service scheduling is an integral part of Microsoft CRM  your staff can easily reference customer histories, demographics, and preferences in scheduling services. This functionality enables you to deliver more personalized, customized service as well as feed customer service histories back into your marketing and sales processes.

For example, an automotive repair shop might define services in Microsoft CRM as brake jobs, front-end alignments, transmission overhauls, and other service offerings. The repair shop might define resources as individual mechanics, vehicle bays, tools, and parts. When a customer calls for a service appointment, any worker in the shop with access to a computer can schedule an appointment. Depending on the service needed and time slots that are open, Microsoft CRM  displays the dates and times that are available. The Suggestion Pane even lists resources and services that the customer has used before. With the customer on the phone, the worker can schedule an appointment in a click. Then the appointment (scheduled and finished) becomes a permanent part of that customer's Microsoft CRM record.

 

 

 

 

 

 

 

 

 


 





 
 

Tuesday, March 5, 2013


CRM 2011 Plugins: Welcome to transactions !

One of the thing about CRM 4.0 plugins is the inability to automatically rollback actions when an exception occurs during a business process.

To illustrate this, imagine a plugin which creates a contract, then a line of contract. If the code throws an exception during the creation of the contract line, you need to take care yourself of deleting the contract that have been created: of course, you need the contract AND the contract line, not just the contract.

In CRM 2011, you can now register your plugin in new stage (see below). That means that you can register your plugin in a transaction (if using stage 20 and 40) and whenever you plugin throws an exception, every action done during the transaction will be rollback. In our previous example, that means tha the contract will be deleted automatically by the application.

Event
Stage Name
Stage Number
Description
Pre-Event
Pre-validation
10
Stage in the pipeline for plug-ins that are to execute before the main system operation. Plug-ins registered in this stage may execute outside the database transaction.
Pre-Event
Pre-operation
20
Stage in the pipeline for plug-ins that are to execute before the main system operation. Plug-ins registered in this stage are executed within the database transaction.
Post-Event
Post-operation
40
Stage in the pipeline for plug-ins which are to execute after the main operation. Plug-ins registered in this stage are executed within the database transaction.
Post-Event
Post-operation
50
Stage in the pipeline for plug-ins which are to execute after the main operation. Plug-ins registered in this stage may execute outside the database transaction. This stage only supports Microsoft Dynamics CRM 4.0 based plug-ins

 

 

Transactional features in Crm 2011

One of the very handy features in Crm 2011 is the fact that plugins now execute within the transaction, not outside it anymore. This means that if an error occurs within a plugin that fires on Create of a record, the actions done by the code gets rolled back AND the actual record created to trigger this event is also rolled back. So no more duplicate records if a plugin fails and the user, thinking that the record did not create, resaves the record.
 
For more information on the pipelines in Crm 2011, see here.