Sometimes, we came across situations to make an Associated View IFrame to be mandatory. However, it is very easy to implement. There are two approaches. First one is, using Java Script to call a web service and check whether current record has at least one associated record. And the second approach is just check whether an IFrame which is used to display associated records has at least one record in it’s grid. The latter approach is very easy to implement and here we go:
1. In the onSave event of crmForm, just check how many records the IFrame grid has
2. If the count is less than one, cancel the Save event and alert the user
3. Set the focus to the “Add Existing Button” of the crmGrid.
function ValidateIFrame()
{
if (crmForm.all.IFRAME_ MyIFrame.readyState == “complete”)
{
if (document.frames(“IFRAME_ MyIFrame”).document.all[‘crmGrid’].InnerGrid.NumberOfRecords < 1)
{
event.returnValue=false;
alert(“Please Select Records”);
var oaddexist=document.frames(‘IFRAME_ MyIFrame’).document.getElementById(‘<id of the add existing button>’);
if(oaddexist)
{
oaddexist.focus();
}
}
}
}
}
{
if (crmForm.all.IFRAME_ MyIFrame.readyState == “complete”)
{
if (document.frames(“IFRAME_ MyIFrame”).document.all[‘crmGrid’].InnerGrid.NumberOfRecords < 1)
{
event.returnValue=false;
alert(“Please Select Records”);
var oaddexist=document.frames(‘IFRAME_ MyIFrame’).document.getElementById(‘<id of the add existing button>’);
if(oaddexist)
{
oaddexist.focus();
}
}
}
}
}
if(crmForm.all.IFRAME_MyIFrame)
{
ValidateIFrame();
}
{
ValidateIFrame();
}
Hope it helps…
Thanks
Vikranth P.