Convert Text Field to Hyperlink
function ConvertToLink(fldName) {
if(Xrm.Page.getAttribute(fldName).getValue()!=null)
{
var content = Xrm.Page.getAttribute(fldName).getValue();
var btn = "<a href='javascript: void(0);' onclick=\"window.open(\'" + content + "\', \'windowname1\', \'width=600, height=650\'); return false;\" style='color:blue;text-decoration:underline !important'>" + content +"</a>";
var ctrl = Xrm.Page.ui.controls.get(fldName)._control;
// Add the new button
ctrl.get_element().innerHTML += btn;
// Hide the textbox
ctrl.get_element().firstChild.style.display = 'none';
}
}
OPEN ENTITY FORM
function OpenRecord(entityName, recordId)
{
Xrm.Utility.openEntityForm(entityName,recordId);
}
Modify Add Existing View
http://danielcai.blogspot.ie/2011/12/filtered-lookup-for-existing-button-of.html
For rollup 12 issues:
FILTERING THE RESULTS USING THE SOAP END POINT
//filters an add existing lookup view (1:N)
function addExistingFromSubGridCustom (gridTypeCode, gridControl, fetch, layout, viewName) {
var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}"; // a dummy view ID
var relName, roleOrd;
if (typeof (gridControl.GetParameter) === "function") { //post rollup 12
relName = gridControl.GetParameter("relName");
roleOrd = gridControl.GetParameter("roleOrd");
}
else { //pre rollup 12
relName = gridControl.getParameter("relName");
roleOrd = gridControl.getParameter("roleOrd");
}
//creates the custom view object
var customView = {
fetchXml: fetch,
id: viewId,
layoutXml: layout,
name: viewName,
recordType: gridTypeCode,
Type: 0
};
//pops the lookup window with our view injected
var lookupItems = LookupObjects(null, "multi", gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
//once the lookup window is closed, we need the parent record ID and ETC before associating selected records
if (lookupItems && lookupItems.items.length > 0)
{
var parentId;
var parentTypeCode;
if (typeof (GetParentObject) == "function")
{ //post rollup 12 has its own function to get this
var parent = GetParentObject();
parentId = parent.id;
parentTypeCode = parent.objectTypeCode;
}
else
{ //pre rollup 12 still needs to use the old way
var parent = typeof (crmFormSubmit) == "undefined" ? $get("crmFormSubmit") : crmFormSubmit; //according to daniels blog crmFormSubmit should already be defined, but it's not...
if (parent) {
parentId = parent.crmFormSubmitId.value;
parentTypeCode = parent.crmFormSubmitObjectType.value;
}
else {
parentId = window.parent.crmFormSubmit.crmFormSubmitId.value;
parentTypeCode = window.parent.crmFormSubmit.crmFormSubmitObjectType.value;
}
}
//associates the selected records
AssociateObjects(parentTypeCode, parentId, gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName);
}
}
//filters the Emision Point 1:N lookup view from Amendment to show only Emision Points Regarding the ammendment!!
function filterAddExistingAmpoints (gridTypeCode, gridControl, primaryEntityName, entityID)
{
var cols = ["amendment"];
var retrievedGroup = CrmServiceToolkit.Retrieve(primaryEntityName, entityID, cols);
//fetch to retrieve filtered data
var fetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
" <entity name='amemissionpoint'>" +
" <attribute name='amemissionpointid' />" +
" <attribute name='name' />" +
" <attribute name='shortcode' />" +
" <attribute name='group' />" +
" <attribute name='emissionpointtype' />" +
" <attribute name='createdon' />" +
" <order attribute='missionpointtype' descending='false' />" +
" <filter type='and'>" +
" <condition attribute='amendment' operator='eq' value='" + retrievedGroup.getValue('amendment') +"' />" +
" </filter>" +
" </entity>" +
"</fetch>";
//columns to display in the custom view (make sure to include these in the fetch query)
var layout = "<grid name='resultset' object='1' jump='amemissionpointid' select='1' icon='1' preview='1'>" +
" <row name='result' id='amemissionpointid'>" +
" <cell name='name' width='200' />" +
" <cell name='shortcode' width='30' />" +
" <cell name='emissionpointtype' width='100' />" +
" <cell name='createdon' width='100' />" +
" <cell name='group' width='100' />" +
" </row>" +
"</grid>";
addExistingFromSubGridCustom(gridTypeCode, gridControl, fetch, layout, "Filtered Emision Points");
}
To hide the lookup view button “new” use the following UNSUPPORTED solution.
//Removing the New button from lookup.
var lookupControl = Sys.Application.findComponent(lookupname);
if (lookupControl != null)
{
lookupControl._element._behaviors[0].AddParam("ShowNewButton", 0);
}
Ribbon Edition with the Ribbon WorkBench
JavaScript Switch Statment to show text boxes depending on Option Set
Simple Javascript function to show-hide areas depending on Option Set Value
function ShowTextBoxesForType()
{
Xrm.Page.getControl("term").setVisible(false);
Xrm.Page.getControl("longdescription2").setVisible(false);
var miOptionSet = Xrm.Page.getAttribute("recordtype");
switch (miOptionSet.getValue())
{
case 1:
Xrm.Page.getControl("term").setVisible(true);
break;
case 4:
Xrm.Page.getControl("longdescription2").setVisible(true);
break;
default:
break;
}
Xrm.Page.getControl("longdescription").setVisible(true);
}
I hope it helps.
CRM and SHAREPOINT Integration
SharePoint Integration
The step by step tutorial can be found here.
Modifying the Buttons on the View
If we want to modify the buttons on the document View (New , Add…) we will have to modify the CRMListComponent following this post instructions.
http://community.dynamics.com/crm/f/117/t/84936.aspx#.UVwVOpPvtqU
A great post about attaching files to notes.
http://lakshmanindian.wordpress.com/2012/11/01/attachments-in-microsoft-dynamics-crm-2011/
