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.