Calculation on Repeating Table Changed Event in InfoPath


We had a requirement of creating an InfoPath form that would use a repeating table and to do certain calculations on the values in rows of the repeating tables and display the result in a separate section.

Here is a screen shot of the same !

infopathCalculation

So above here, based on activity selected and time spent specified for it, the Total hours and Total days ( total hours/ 8) needs to be calculated.

Here is the sample code for that

public void group7_Changed(object sender, XmlEventArgs e)
       {
           // Create an XPathNavigator from the main data source
           XPathNavigator domNav = MainDataSource.CreateNavigator();
           // Create an XPathNodeIterator to iterate through all the rows
           XPathNodeIterator rows = domNav.Select(
           "/my:myFields/my:group6/my:group7", NamespaceManager);
           // Create Navigator for each of the fields where total needs to be displayed
           XPathNavigator lblTotalSpecHours = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblSpecHours", NamespaceManager);
           Int32 intTotalSpecHours = 0;
           XPathNavigator lblTotalConsultancyHours = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblTotalConsulHours", NamespaceManager);
           Int32 intTotalConsultancyHours = 0;
           XPathNavigator lblTotalDevelopmentHours = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblTotalDevHours", NamespaceManager);
           Int32 intTotalDevelopmentHours = 0;
           XPathNavigator lblTotalTestingHours = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblTotalTestingHours", NamespaceManager);
           Int32 intTotalTestingHours = 0;
           XPathNavigator lblTotalDeploymentHours = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblTotalDepHours", NamespaceManager);
           Int32 intTotalDeploymentHours = 0;

           // loop through all the rows of repeating table
           while (rows.MoveNext())
           {
               // Get values for Activity dropdown field and Time Spent field
               string fldActivity = rows.Current.SelectSingleNode(
               "my:ddlActivity", NamespaceManager).Value;
               string fldTimeSpent = rows.Current.SelectSingleNode(
               "my:txtTimeSpent", NamespaceManager).Value;                 

               if (fldActivity == "Specification" && fldTimeSpent!="")
               {
                   intTotalSpecHours += Convert.ToInt32(fldTimeSpent);                       
               }

               if (fldActivity == "Consultancy" && fldTimeSpent != "")
               {
                   intTotalConsultancyHours += Convert.ToInt32(fldTimeSpent);
               }

               if (fldActivity == "Development" && fldTimeSpent != "")
               {
                   intTotalDevelopmentHours += Convert.ToInt32(fldTimeSpent);
               }

               if (fldActivity == "Testing" && fldTimeSpent != "")
               {
                   intTotalTestingHours += Convert.ToInt32(fldTimeSpent);
               }
               if (fldActivity == "Deployment" && fldTimeSpent != "")
               {
                   intTotalDeploymentHours += Convert.ToInt32(fldTimeSpent);
               }          

           }

           // for Specification
           RemoveNilAndSetHours(lblTotalSpecHours, intTotalSpecHours);
           XPathNavigator lblTotalSpecDays = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblSpecDays", NamespaceManager);
           RemoveNilAndSetDays(lblTotalSpecDays, intTotalSpecHours);       

           // for Consultancy
           RemoveNilAndSetHours(lblTotalConsultancyHours, intTotalConsultancyHours);
           XPathNavigator lblTotalConsultancyDays = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblTotalConsulDays", NamespaceManager);
           RemoveNilAndSetDays(lblTotalConsultancyDays, intTotalConsultancyHours);

           //// for Development
           RemoveNilAndSetHours(lblTotalDevelopmentHours, intTotalDevelopmentHours);
           XPathNavigator lblTotalDevelopmentDays = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblTotalDevDays", NamespaceManager);
           RemoveNilAndSetDays(lblTotalDevelopmentDays, intTotalDevelopmentHours);

           //// for Testing
           RemoveNilAndSetHours(lblTotalTestingHours, intTotalTestingHours);
           XPathNavigator lblTotalTestingDays = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblTotalTestingDays", NamespaceManager);
           RemoveNilAndSetDays(lblTotalTestingDays, intTotalTestingHours);

           //// for Deployment
           RemoveNilAndSetHours(lblTotalDeploymentHours, intTotalDeploymentHours);
           XPathNavigator lblTotalDeploymentDays = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:lblTotalDepDays", NamespaceManager);
           RemoveNilAndSetDays(lblTotalDeploymentDays, intTotalDeploymentHours); 
       }

       // RemoveNil for the fields and set value
       public void RemoveNilAndSetDays(XPathNavigator xpathNav, int totalHours)
       {
           if (xpathNav.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
               xpathNav.DeleteSelf();
           int days = totalHours / 8;
           xpathNav.SetValue(days.ToString());
       }

       public void RemoveNilAndSetHours(XPathNavigator xpathNav, int totalHours)
       {
           if (xpathNav.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
               xpathNav.DeleteSelf();
           xpathNav.SetValue(totalHours.ToString());
       }

 

 

Change the extension of the file from .doc to .xsn !!!

Bye..

Schema validation found non-data type errors in InfoPath


We could get the above error while trying to set value for a field using XPathNavigator. The reason could be that the field has the nil attribute set

Most of the fields with the exception of String Type uses nil to indicate “no value”.

So before we could set the value for those fields, we need to remove the nil attribute from it.

We could use the below code for that.


XPathNavigator node= MainDataSource.CreateNavigator()

.SelectSingleNode(“/my:myFields/my:lblSpecHours”, NamespaceManager);

if (node.MoveToAttribute(“nil”,

http://www.w3.org/2001/XMLSchema-instance”))

node.DeleteSelf();

node.SetValue(txtValue);


Bye..

One of the best site for InfoPath developers


I was assigned a certain task in InfoPath, and while browsing for some help, i found this site.

http://www.bizsupportonline.net/

It seemed like one of the best sites as far as InfoPath development and SharePoint integration part of it are concerned.

 

Bye..

Building URL to the CRM record that triggers the workflow.


Hi,

I was just looking for the various options for the above scenario.

These are the different options that i found

http://www.dynamicscrmtrickbag.com/2009/09/13/email-record-links/

http://www.powerobjects.com/blog/2009/02/23/crm-40-links-in-workflow-emails-part-2/

http://blog.powerobjects.com/2008/09/16/crm-40-links-to-entities-in-workflow-email/

http://a33ik.blogspot.com/2009/06/creation-of-shortcut-to-record-in.html

and finally using ‘Url Functions’ extensions found in

Business Productivity Workflow Tools

find more information on it over here

http://blog.customereffective.com/blog/2009/10/make-microsoft-dynamics-crm-workflow-more-useful.html

Bye.

Passing parameters to NavBarItem’s url property in CRM.


For passing custom attribute values as parameter to the navBarItem on an Entity, we could use the following similar JavaScript

 

// get the id of navbaritem using IE Dev tool

var navBarItem = document.all.navBarItemID;

// get the value of the field to pass as parameter

var fname=crmForm.all.firstname.DataValue;

// if it is not null than attach a function that uses openIsvWin function of CRM

// there you could pass your parameters for the url

if (navBarItem != null) {

navBarItem .onclick = function() {

openIsvWin(‘http://localhost/default.aspx?fname=’+fname, false, -1, ”);

}

}

http://www.eggheadcafe.com/software/aspnet/29468928/navbaritem-url-property.aspx

 

Bye..

“Insert failed for entity ‘TimeZoneLocalizedName’, batchRows=1144 with exception System.Data.SqlClient.SqlException: Cannot bulk load because the file "C:\Documents and Settings\\Application Data\Microsoft\MSCRM\BCP\.bcp" could not be opened” in Data Migration Manager


I got this error in data migration manager at the synchronizing stage.

While searching for it I found that this error occurs in case if we have installed Data Migration Manager on the CRM Server and have selected the SQL Server on a remote machine as database.

The error got resolved on re installing the Data Migration Manager with SQL Express.

Bye..