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

Monday, March 21, 2011

Steps to Add Deployment Administrator in MSCRM 4.0 from Database


Hello friends,

After a long busy schedule, today I want to share my one of the recent experience when I was caught in a problem which was arise by my small mistake J and then I managed to overcome to the solution.

Recently we needed import one of our CRM organizations from one deployment to other but due to some technical reasons the import got failed. Due to that failure before restarting import again, I needed to remove all the false entries which got created in MSCRM_CONFIG database during the failed import action. Within few minutes I managed to remove all the referential entries from all the tables related to the failed to import organization. 

But later on when I opened Deployment Manager, it did not allowed me to open it and responded me with below error
“Only the administrators are able to use deployment manager. you are not a deployment administrator.”
and later on I found that during the deletion of the false entries, by mistake all the entries related to deployment managers also got deleted.

After searching for couple of hours I managed to add Deployment Administrator from database and I want to share you the steps I followed to achieve the same.

Step 1: Get "systemuserid" for the user whom you want as a "Deployment Administrator" from CRM Database
Query: 
select systemuserid,fullname from systemuser where fullname like '%prathmesh%'

Step 2: Open SQL Server Management Studio and fire below query against MSCRM_CONFIG database
Query: 
SELECT Id, UserId
FROM SystemUserOrganizations
WHERE CrmUserId = <<systemuserid>> --Replace <> by the systemuserid got from step 1

Step 3: Fire Below query to get Administrator Security Role Id
Query:
SELECT Id FROM SecurityRole WHERE name = 'Administrator'

Step 4: Fire below query to Insert a record in SystemUserRoles table of MSCRM_CONFIG database
Query:
INSERT INTO SystemUserRoles
(
     [Id]
     ,[SecurityRoleId]
     ,[SystemUserId]
     ,[IsDeleted]
)
VALUES
(
     NEWID(), -- new Guid
     ,<<SecurityRoleId>>  --Replace "Id" Guid found from Step 3
     ,<<UserId>> --replace "UserId" Guid found from step 2
     ,0
)

Step 5: Add Name to SystemUser table using below query
Query:
UPDATE SystemUser
SET name  <<mydomain\username>>  -- User's domain name\username
WHERE Id = <<UserId>>  -- Replace "UserId" Guid found from step 2


Hope this post helps you jump out of a situation in which I was caught… J

Feel free to post the query in case you need help for Dynamics CRM and this post.