Displaying Image from File Attachment control in InfoPath form inside SSRS report.


I was assigned the task of displaying images attached to InfoPath form using file attachment control in one of the SQL Server Reporting Services Report.

For this we need to add an image control and set it’s property in the following manner

Image Source :- Database

Then select appropriate DataSet, Image Field and MimeType

Here to display the Image properly we need to write a Report Assembly with the following code.

public static class FileDecoder
    {
        /// <summary>
        /// Takes string value for image from the infopath form
        /// and converts it to proper bytes for displaying it as an image
        /// </summary>
        /// <param name="imageData">string representation of the image</param>
        /// <returns>corrected byte array</returns>
        public static byte[] GetCorrectedByte(string imageData)
        {
            byte[] attachmentNodeBytes = Convert.FromBase64String(imageData);
            // Position 20 contains a DWORD indicating the length of the
            // filename buffer. The filename is stored as Unicode so the
            // length is multiplied by 2.
            int fnLength = attachmentNodeBytes[20] * 2;
            // The file is located after the header, which is 24 bytes long
            // plus the length of the filename. 
            byte[] fileContents = new byte[attachmentNodeBytes.Length – (24 + fnLength)];

            for (int i = 0; i < fileContents.Length; ++i)
            {
                fileContents[i] = attachmentNodeBytes[24 + fnLength + i];
            }

            return fileContents;
        }

    }

 

And set the value for image control as

=(Namespace).FileDecoder.GetCorrectedByte(Fields!fieldName.Value)

ImageFromDB

 

Bye..

InfoPath forms and SQL Server Reporting Services


Hi,

I recently worked on a report project having InfoPath form in SharePoint’s InfoPath library as it’s Data Source.

For understanding purpose let’s start with a very simple InfoPath form having two text boxes in it named txtFirstName and txtLastName.

Form

Let’s first define a Data Source for our report.

Name:- InfoPathDataSource

Type:- XML

Connection String : (Suppose the url for our InfoPath library is following

http://nrana-1710-vm1:2575/Sample/Forms/AllItems.aspx and the name of the InfoPath form is PersonalInfo.

So in this case our connection string would be

http://nrana-1710-vm1:2575/Sample/PersonalInfo.xml

Now let’s create a new DataSet having InfoPathDataSource as its data source.

Name :- InfoPathDataSet

Data source :- InfoPathDataSource

Command Type :- Text

Query String :-  ( For defining query string we need to first open up the PersonalInfo.xml file. Paste the following url in IE http://nrana-1710-vm1:2575/Sample/PersonalInfo.xml and download and open the xml file.

Suppose this is the content of the PersonalInfo.xml file

<?xml version="1.0" encoding="utf-8"?>
<?mso-infoPathSolution
name="urn:schemas-microsoft-com:office:infopath:Sample:-myXSD-2010-05-26T09-16-03"
solutionVersion="1.0.0.10"
productVersion="12.0.0.0"
PIVersion="1.0.0.0"
href="
http://nrana-1710-vm1:2575/Sample/Forms/template.xsn"?>
<?mso-application
progid="InfoPath.Document"
versionProgid="InfoPath.Document.2"?>

<my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-05-26T09:16:03" xml:lang="en-US">
    <my:txtFirstName>Nishant </my:txtFirstName>
    <my:txtLastName>Rana</my:txtLastName>
</my:myFields>

The  Query String to retrieve First and Last name value would be

<Query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-05-26T09:16:03"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
    <ElementPath>
        my:myFields           
    {
        my:txtFirstName(String),
        my:txtLastName(String)       
    }
    </ElementPath>
</Query>

We also define a parameter in our data set to which we would pass the url to the infopath form i.e.

http://nrana-1710-vm1:2575/Sample/PersonalInfo.xml

That’s it, now if we run the query we can get values for first name and last name.

In case if your InfoPath xml form is looks like this

<my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-05-12T05:10:51" xml:lang="en-US">
    <my:group1>
        <my:group2>
            <my:field1>2</my:field1>
            <my:field2>nishu</my:field2>………….

Than the Element Path of Query String would be like

<ElementPath>
        my:myFields/my:group1/my:group2          
    {
        my:field1(String),
        my:field2(String)       
    }
    </ElementPath>

Bye…

Changing default filter for Contracts Associated View for Account.


For an account record, the associated view of Contract would have default filter set as Draft. So if we want to change it to some other status for example “Active” we can make use of the following JavaScript for that.

This JavaScript is based on the popular JavaScript code used for hiding “add existing button”

Please check this wonderful article

http://blog.davehawes.com/post/2008/04/23/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx

The JavaScript code for changing default option

var navElement = document.getElementById('navContracts');
 if (navElement != null) {
  navElement.onclick = function LoadAreaOverride()  {
   loadArea('areaContracts');
   SetDefaultOption(document.getElementById('areaContractsFrame'));
  }
 }

function SetDefaultOption(Iframe) {
 if (Iframe != null ) {
  Iframe.onreadystatechange = function SetOption() {
   if (Iframe.readyState == 'complete') {
    var iFrame = frames[window.event.srcElement.id];
    var selectBox=iFrame.document.getElementById('statecode');
     selectBox.options[2].selected=true;
   }
  }
 }

http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/85615ccd-b8e9-48d3-a906-4fd7b301dac0

Bye..

Good resource for SQL Server Reporting Services


Hi,

Please check out this wonderful article.

http://www.ssw.com.au/ssw/standards/rules/rulesToBetterSQLReportingServices.aspx

Bye..

Understanding PrimaryEntityImage, PrimaryEntityPreImage and PrimaryEntityPostImage for Custom Workfow Activity in CRM 4.


Suppose we have written a simple workflow activity that references values for the above Images and have registered it on create of lead record.

The attributes included within the images would be following

Record is created Lead
   
PrimaryEntityImage fullname
  leadid
  owningbusinessunit
   
PrimaryEntityPreImage null
   
PrimaryEntityPostImage leadid
  owningbusinessunit
  ownerid
   

 

Now suppose we register it on Record attribute change and select city and description for lead.

Now suppose we specify value for those fields and save the record. Here the values for the images would be

Record attributes change Lead
   
PrimaryEntityImage fullname
  leadid
  owningbusinessunit
   
PrimaryEntityPreImage fullname
  leadid
  owningbusinessunit
  ownerid
   
PrimaryEntityPostImage leadid
  owningbusinessunit
  ownerid
   

 

Except for values in PrimaryEntityPreImage there is hardly any change in the Images.

Now lets modify the workflow and add a check condition step that would check if both the city and description field contains data for lead.

Now after modifying the values for city and description field for a lead ,these are the values we get in the images.

Record attributes change (after check condition) Lead
   
PrimaryEntityImage fullname
  leadid
  owningbusinessunit
  address1_city
description
   
PrimaryEntityPreImage fullname
  leadid
  owningbusinessunit
  ownerid
  address1_city
description
   
PrimaryEntityPostImage leadid
  owningbusinessunit
  ownerid

 

Address1_city and Description field has got added for PrimaryEntityImage and PrimaryEntityPreImage.

Now if we remove check condition for city field for lead,

Record attributes change (after check condition) Lead
   
PrimaryEntityImage fullname
  leadid
  owningbusinessunit
  description
   
PrimaryEntityPreImage fullname
  leadid
  owningbusinessunit
  ownerid
  description
   
PrimaryEntityPostImage leadid
  owningbusinessunit
  ownerid

 

We could see that address1_city is not there in the images.

Now lets further modify our workflow, remove the check condition and add a step to create an account record and set dynamic values for fields in account using the industrycode and emailaddress1 field of the lead record.

Record attributes change (Step for Creating Record) Lead
   
PrimaryEntityImage fullname
  leadid
  owningbusinessunit
  industrycode
emailaddress1
   
PrimaryEntityPreImage fullname
  leadid
  owningbusinessunit
  ownerid
  industrycode
emailaddress1
   
PrimaryEntityPostImage leadid
  owningbusinessunit
  ownerid

 

We can see that both these fields are added to images.

And here PrimaryEntityPreImage would contain the values for the field before they were modified and and PrimaryEntityImages would contain the modified values for those field. The PrimaryEntityPostImage would not have these attributes inside it.

So it proves that an attribute would be included in the entity images if we are referencing that property in our Check Condition or as a dynamic value within the workflow.

Bye.

IPluginExecutionContext and IWorkflowContext properties.


Hi,

Check out this link

Context Properties

Bye..