Wednesday, October 26, 2011

Add a button to MS CRM 2011 Form Header

Hi,

Few days back I had a request to have a button in CRM Form Header. I wondered about the request and started working on its feasibility study. While searching and googling around I found this link which described about adding a button to CRM Form. I took this post as a help and started working on the same, as CRM header fields are not available to us during form onload event. I had to change some of the scripts to make it available for Header. Find below script for the same.

Solution:
1. Create a new text field on CRM 2011 form (type: Multiple Lines of Text).
2. Add the new text field in the Form Header.
3. Add below script function to Form OnLoad event.

function ConvertHeaderFieldToButton(fieldname, buttontext, buttonwidth, clickevent, title)
{
//check if object exists; else return
if (document.getElementById('header_'+fieldname+'_d') == null)
{
 return;
}

var divField = document.getElementById('header_'+fieldname+'_d').all[0];

var btnField = document.createElement("button");

btnField.setAttribute('type','button');
btnField.setAttribute('name',buttontext);
btnField.setAttribute('readonly','readonly');

btnField.style.borderRight="#3366cc 1px solid";
btnField.style.paddingRight="5px";
btnField.style.borderTop="#3366cc 1px solid";
btnField.style.paddingLeft="5px";
btnField.style.fontSize="11px";
btnField.style.backgroundImage="url(/_imgs/btn_rest.gif)";
btnField.style.borderLeft="#3366cc 1px solid";
btnField.style.width=buttonwidth;
btnField.style.cursor="hand";
btnField.style.lineHeight="18px";
btnField.style.borderBottom="#3366cc 1px solid";
btnField.style.backgroundRepeat="repeat-x";
btnField.style.fontFamily="Tahoma";
btnField.style.height="20px";
btnField.style.backgroundColor="#cee7ff";
btnField.style.textAlign="center";
btnField.style.overflow="hidden";
btnField.style.lineHeight="14px";
btnField.title=title;

btnField.attachEvent("onmousedown",push_button);
btnField.attachEvent("onmouseup",release_button);

//add your if condition for respective buttons' click event
if (clickevent == ButtonOnClick)
btnField.attachEvent("onclick",ButtonOnClick);

if (document.getElementById('header_'+fieldname+'_c') != null)
    document.getElementById('header_'+fieldname+'_c').style.visibility = 'hidden';

btnField.appendChild(document.createTextNode(buttontext));

divField = divField.appendChild(btnField);

window.focus();

function push_button()
{
window.event.srcElement.style.borderWidth="2px";
window.event.srcElement.style.borderStyle="groove ridge ridge groove";
window.event.srcElement.style.borderColor="#3366cc #4080f0 #4080f0 #3366cc";
}

function release_button()
{
window.event.srcElement.style.border="1px solid #3366cc";
}

// add a function to call for each button added to header
// definition of the function to call on button click
function ButtonOnClick()
{
alert('Button Click');
}
}

And you are done with your task of adding a button to CRM Form Header.

Hope you find this post helpful for your relevant task.
Feel free to post the query in case you need any aid for Dynamics CRM and this post.

Thanks !!! J

Remove Dashboard menu from workplace area in MSCRM 2011

Hi All,

Recently I got one request to remove dashboard menu from workplace area in CRM 2011.

Solution:
1. Export your solution from CRM 2011
2. Open customizations.xml file from the exported solution folder.
3. Goto XPath: ImportExportXml -> SiteMap -> SiteMap -> Area (workplace) -> Group (MyWork)
4. Remove the below tag from the above path

<SubArea Id="nav_dashboards" ResourceId="Homepage_Dashboards" Icon="/_imgs/area/18_home.gif" DescriptionResourceId="Dashboards_Description" Url="/workplace/home_dashboards.aspx" GetStartedPanePath="Dashboards_Web_User_Visor.html" GetStartedPanePathAdmin="Dashboards_Web_Admin_Visor.html" GetStartedPanePathOutlook="Dashboards_Outlook_User_Visor.html" GetStartedPanePathAdminOutlook="Dashboards_Outlook_Admin_Visor.html" />

5. Import the solution to CRM.

Check it out that Dashboard menu will be removed from your workplace area. 

In case if you again want to make it visible, paste the above tag to the same xPath and you the menu item will again be visible for use.

Hope you find this post helpful.

Thank You !!! J

To use this saved view, you must remove criteria and columns that refer to deleted or non-searchable items

Hi,

After a long time, today I would like share one of the issue which I faced during my work with CRM 2011.
I added some new fields to my new custom entity and wanted the field level security for them. I went to Settings -> Administration -> Field Security Profiles and opened one of my existing profile. At this moment I got an error as below.

"To use this saved view, you must remove criteria and columns that refer to deleted or non-searchable items."

After searching for this error about an hour, I realized that before creating new fields of the custom entity, I have deleted another custom entity which has some of its fields having field level security enabled on them and were used in the same exiting profile which I needed for the new fields.

Solution:
Solution to this issue was really very simple. We just need to delete the fields of the deleted entity from the field level security profile.

Delete the records from FieldPermissionBase table where attribute is used (attributelogicalname) or all the fields of the deleted entity having field level security enabled.

Query to delete attributes: 

-- Replace respective entity objecttypecode with 10003 below
DELETE FROM FieldPermissionBase
where EntityName = '10003'

And finally the above error will be vanished and you are just good to go on with your work... 

Hope this solution helps you to get rid of this error and happily move on with CRM 2011. 
Feel free to post the query in case you need any aid for Dynamics CRM and this post.

Thank You !!! J