-
Book Overview & Buying
-
Table Of Contents
Microsoft Dynamics CRM 2011 Scripting Cookbook
By :
One of the most common requirements that you will eventually encounter is to block a form from getting saved if a certain condition is not met.
Use any of the previously created solutions, or if starting at this recipe create a new solution for this exercise. Add the Contact entity to your solution.
To block events, perform the following steps:
Within your solution, navigate to Entities | Contact | Forms and open the Contact main form for editing. Add a new field of type Two Options. Name it Can Save (new_cansave) and leave the default Yes and No values.
Add the field to your form.
Save and publish the form.
Add a new web resource named JS Event Blocking (new_JSEventBlocking).
Insert the following code:
function BlockSave(context)
{
var _canSave = Xrm.Page.getAttribute("new_cansave").getSelectedOption().text;
if(_canSave == "No")
{
Xrm.Page.context.getEventArgs().preventDefault();
}
}Save and publish the resource.
Associate the BlockSave function...
Change the font size
Change margin width
Change background colour