Monthly Archives: February 2011

Dynamics CRM 4.0 custom workflow activity for retreiving newly created entity Id

Use this code in a custom workflow to extract the guid of a newly created entity. This custom workflow activity also has the ability to return a link to the edit page of the entity. After registration you can call this activity from a standard workflow to, for example, put a link in an email body.

Simple Javascript to hide/show div tag

This sample javascript will hide or show a div when user clicks the other div in browser.

<script type=”text/javascript” language=”javascript”>
    function hideElement(name) {
        if (document.getElementById(name).style.visibility == ‘hidden’) {
            document.getElementById(name).style.visibility = ‘visible’;           
        }
        else
            document.getElementById(name).style.visibility = ‘hidden’;
    }

</script>
<div id=”mydiv” onclick=”hideElement(‘Div1’)” style=”background-color:Green”>test</div>
<div id=”Div1″ style=”background-color:Blue”>test2</div>

Show a link to document properties in Sharepoint 2010 search result

Using XSL transformation you can edit the apperance of the search results in Sharepoint 2010. One of the most commonly missed features of the default search result is the lack of a hyperlink to a documents properties (eg. DispForm.aspx). Such a link gives the users a chance to preview document properties before eventually opening the document with Word/Excel/Adoboe etc.

Here XSL code to add a hyperlink to the document properties, and also a link to the containing document library. It will also work for Sharepoint 2007. Paste the code into the search results web part using the XSL editor at the appropriate place.

Important. You must register metadata properties ItemID (ows_ID(text)) and Basic4 (Basic:4 (text)) and do a full crawl from Central Admin.

<div class=”srch-Title3″>
<xsl:variable name=”itemid” select=”ItemID”/>
<xsl:choose>
<xsl:when test=”contentclass[. = ‘STS_ListItem_DocumentLibrary’]”>
<xsl:choose>
<xsl:when test=”contains(basic4,’http’)”>
<xsl:variable name=”library” select=”substring-after(substring-after(url,basic4),’/’)” />
<xsl:variable name=”displayUrl” select=”concat(basic4, ‘/’, substring-before($library,’/’),’/Forms/DispForm.aspx?ID=’,itemid)” />
<a href=”{$displayUrl}”>
Show properties
</a>
</xsl:when>
<xsl:otherwise>
<xsl:variable name=”DocLib” select=”substring-after(substring-after(url,sitename),’/’)” />
<xsl:variable name=”MetaDataPath” select=”concat(sitename, ‘/’, substring-before($DocLib,’/’),’Forms/DispForm.aspx?ID=’,itemid)” />
<a href=”{$MetaDataPath}”>
Show properties
</a>
</xsl:otherwise>

</xsl:choose>
<a href=”{sitename}”>
Show library
</a>
<br></br>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</div>

More reading: For a full walkthrough of editing search result check out this great article by Jesse Kim. SharePoint 2010: Actionable search results for documents

Edit: Here’s the full XSL: https://danielbergsten.wordpress.com/2011/09/22/show-a-link-to-document-properties-in-sharepoint-2010-search-result-part-2/

CRM 2011 Javascript for hiding a field based on another fields value

This script will hide or show a certain fields control based on the value of another field on the form. In this sample a ‘Two Option’ field is used to determine if a dropdownlist should be hidden. Modify to suit your needs.

function SetControlInvisible(field, dependantField) {
    //get control for field
    var control = Xrm.Page.ui.controls.get(field);
    if ((control != “undefined”) && (control != null))
    {
        //get control for dependant field
        var dependantControl = Xrm.Page.ui.controls.get(dependantField);
        if ((dependantControl != “undefined”) && (dependantControl != null)) {
            var attribute = dependantControl.getAttribute();
            var depandantFieldValue = attribute.getValue();
            //set visible based on depandant fields value
            if (depandantFieldValue == false) {
                control.setVisible(false);
            }
            else {
                control.setVisible(true);
            }
        }
        else {
            alert(‘control not found ‘ + dependantField);
        }
    }
    else {
        alert(‘control not found ‘ + field);
    }
}

Register the script with the form onLoad and field onChange events. Passing the names of the fields as parameters.

image

ClickOnce shows blank page under IIS 7.0 (Static content not installed)

Symptoms: I published a ClickOnce applikation on a Windows 2008 R2 Server running IIS 7.0. But when trying to access  the publish.htm or setup.exe or xxx.application files IIS only responds with an empty html page. No error messages or event logs.

Another symptom is that the “Welcome to IIS 7.0” start page under http://localhost is also blank.

Resolution: Install the web server role service “Static content”. Here’s a how to: http://support.microsoft.com/kb/2196177 (Browsing to static content returns a blank page or HTTP 500 Server Error message in Internet Information Services (IIS) 7.0 and 7.5)

CRM 2011 Javascript to set IFRAME url

Use a script like this to set the url of your IFRAME based on current records ID. Add a web resource javascript library and register it for the onLoad event passing, as strings, the url to your report and the name of your iframe.

function SetReportUrl(reportUrl, iFrame) {

 var customerId = Xrm.Page.data.entity.getId();
 
 if (customerId == null) {
  Xrm.Page.getControl(iFrame).setVisible(false);
 }
 else {  
  Xrm.Page.getControl(iFrame).setSrc(reportUrl + "&id=" + customerId);
 }
}

Parameters:

reportUrl = ‘http://indexdb/ReportServer/Pages/ReportViewer.aspx?%2fDevelopment_MSCRM%2fKeyValues&rs:Command=Render&rc:Toolbar=false&rs:ClearSession=true&#8217;;

iFrame = ‘IFRAME_report’;

Request for the permission of type ‘Microsoft.SharePoint.Security.SharePointPermission failed

Background: Deploying a aspx web application within a Sharepoint site. Such as C:\inetpub\wwwroot\wss\VirtualDirectories\80\CustomWeb.

Security Exception
Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type ‘Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ failed.

Solution: Add this line to your applications web.config file, system.web section:

<trust level=”Full” originUrl=”” />

or

<trust level=”WSS_Medium” originUrl=”” />

Explanation: By default WSS/MOSS is configured with a security policy called WSS_Minimal.  This policy definition doesn’t grant access to the SP object model.