Wednesday, February 20, 2013

CDC Software Pivotal CRM 6.0: How to execute another client task method with parameters.

Yes it is possible to call another client task method with parameters.
It can be useful for specific things like using Client Forms as custom dialogs.

The caller:
// Get action service
IActionService actionService = ClientContext.ClientAPIService.GetService<IActionService>();

// Create action target object
IClientTaskActionTarget clientTaskActionTarget = actionService.CreateActionTarget<IClientTaskActionTarget>();
clientTaskActionTarget.ClientTask = "MyCompany.PivotalProject.Client";
clientTaskActionTarget.ClientTaskMethod = "MyMethod";
clientTaskActionTarget.Parameters = new object[] { 
 "parameter 1", "parameter 2", "parameter 3"
};

// Create action and execute it.
IAction action = actionService.CreateAction("MyActionName", ActionCommand.Show, ActionContent.ClientTask, clientTaskActionTarget);
actionService.ExecuteAction(action);
The calling method:
public void MyMethod(string p1, string p2, string p3){
 // ... Do something
}

Wednesday, January 9, 2013

CDC Software Pivotal CRM 6.0: Adding custom button to buttons bar.

Someone asked me today how to add custom button bar button to a client form.
Very simple :)

// Get action service
IActionService actionService = ClientContext.ClientAPIService.GetService<IActionService>();

// Create client task action target
IClientTaskActionTarget clientTaskActionTarget = actionService.CreateActionTarget<IClientTaskActionTarget>();
clientTaskActionTarget.ClientTask = "Pivotal.Client.FormTask";
clientTaskActionTarget.ClientTaskMethod = "CustomButtonClickHandler";

// Create action            
IAction action = actionService.CreateAction("CustomButtonClickActionName", ActionCommand.Show, ActionContent.ClientTask, clientTaskActionTarget);

// Create custom button (requires Pivotal.Engine.UI.DataTypes.dll)
ButtonBarButton button = new ButtonBarButton(){
 Name = "CustomButton",
 DisplayName = "My Custom Button",
 Enabled = true
};

// Set custom button action
button.SetAction(action);

// Add custom button to a center content buttons bar
this.ButtonBar.Buttons.Add(button);

Sunday, November 25, 2012

CDC Software Pivotal CRM 6.0: Using Pivotal Input Dialog.


Pivotal Input Dialog may be useful if you want to ask user some input parameters without creating a new client form.
I didn't find any documentation about how exactly to use Pivotal Input Dialog.
So I'm going to publish some code examples here how to use it.

Required dlls:

Pivotal.Engine.Client.Services.Interfaces.dll
Pivotal.Engine.UI.DataTypes.dll

// Get input dialog service
IInputDialogService inputDialogService = ClientContext.ClientAPIService.GetService<IInputDialogService>();
DialogParam dialogParameter = new DialogParam();
dialogParameter.FormParams = new CdcSoftware.Pivotal.Engine.UI.DataTypes.FormParams.InputParamsCollection();

// 1. Foreign Key
Table companyTable = this.SystemClient.UserProfile.GetMetaItem<Table>("Company");
InputParam foreignKeyInputParam = new InputParam()
{
    Label = "Company",
    Type = InputParamType.RForeignField,
    IsRequired = true,
    Enums = companyTable.Id
};
dialogParameter.FormParams.Add(foreignKeyInputParam);

// 2. Single value fields: Date, Boolean, Integer, Double and etc
InputParam dateInputParam = new InputParam() { Label = "Date", Type = InputParamType.Date };
dialogParameter.FormParams.Add(dateInputParam);

InputParam boolInputParam = new InputParam() { Label = "Boolean", Type = InputParamType.Boolean };
dialogParameter.FormParams.Add(boolInputParam);

InputParam intInputParam = new InputParam() { Label = "Integer", Type = InputParamType.Integer };
dialogParameter.FormParams.Add(intInputParam);

// 2. Combo, ListBox
object[] comboValues = new object[] { "value 1", "value 2" };
InputParam comboInputParam = new InputParam() { Label = "Date", Type = InputParamType.RCombo, Enums = comboValues };
dialogParameter.FormParams.Add(comboInputParam);

// Set dialog type
dialogParameter.DialogType = ModalDialogTypeEnum.modalDialogParamsAndDescription;

// Show dialog
inputDialogService.ShowDialog(dialogParameter, "Title");

// Get parameter values
if (foreignKeyInputParam.Value != null)
{
    Id companyId = Id.Create(foreignKeyInputParam.Value);
}

if (intInputParam.Value != null)
{
    int intValue = TypeConvert.ToInt32(intInputParam.Value);
}
You can discover other input parameters types by yourself.

Sunday, August 5, 2012

CDC Software Pivotal CRM 6.0: How to get acces to SearchView.SearchData.ResultsViewControl control.

We can't modify SearchView.SearchData.ResultsViewControl in a usual way because it has an internal get accessor.
But we can use reflection.

Here is an example how to change SearchView rows text color deppending on received data.

1. Add the following dll references to your project:
  • Pivotal.CommonControls.dll
  • CdcSoftware.Ios.UI.dll

2. Register "OnSearchCompleted" notification event handler:
[NotificationEvent("OnSearchCompleted", Table = "Support_Incident")]
public void OnSupportIncidentSearchCompleted(object notifyParams)
{
 ...
}

3. Get DataGridView control via reflection.
CdcSoftware.Pivotal.CommonControls.ResultsViewControl resultsViewControl = searchView.SearchData.GetType().GetProperty("ResultsViewControl").GetValue(searchView.SearchData, null) as CdcSoftware.Pivotal.CommonControls.ResultsViewControl;
if (resultsViewControl != null)
{
CdcSoftware.Pivotal.CommonControls.PivotalDataGridView dataGridView = resultsViewControl.GetType().GetField("_dataGridView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(resultsViewControl) as CdcSoftware.Pivotal.CommonControls.PivotalDataGridView;
}

4. Modify you want.

The full code example:
[NotificationEvent("OnSearchCompleted", Table = "Support_Incident")]
        public void OnSupportIncidentSearchCompleted(object notifyParams)
        {
            ISearchView searchView = ClientContext.ClientAPIService.GetActiveContentObject() as ISearchView;
            if (searchView != null)
            {
                //Get ResultsViewControl
                CdcSoftware.Pivotal.CommonControls.ResultsViewControl resultsViewControl = searchView.SearchData.GetType().GetProperty("ResultsViewControl").GetValue(searchView.SearchData, null) as CdcSoftware.Pivotal.CommonControls.ResultsViewControl;

                if (resultsViewControl != null)
                {
                    //Get DataGridView control
                    CdcSoftware.Pivotal.CommonControls.PivotalDataGridView dataGridView = resultsViewControl.GetType().GetField("_dataGridView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(resultsViewControl) as CdcSoftware.Pivotal.CommonControls.PivotalDataGridView;
                    
                    //Attach RowPostPaint event
                    dataGridView.RowPostPaint += new DataGridViewRowPostPaintEventHandler((object sender, DataGridViewRowPostPaintEventArgs e) =>
                    {
                        CdcSoftware.Pivotal.CommonControls.PivotalDataGridView pivotalDataGridView = sender as CdcSoftware.Pivotal.CommonControls.PivotalDataGridView;
                        if (dataGridView.Columns.Contains("Status_Id@Rn_Descriptor"))
                        {
                            //Color closed incidents
                            string columnTextValue = Convert.ToString(pivotalDataGridView.Rows[e.RowIndex].Cells["Status_Id@Rn_Descriptor"].Value);
                            if (columnTextValue.Contains("Closed"))
                            {
                                pivotalDataGridView.Rows[e.RowIndex].DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
                            }
                        }
                    });
                }
            }
        }

Regards,
Max Shafranski

Wednesday, August 1, 2012

Another way to preview reports and other file types in Pivotal Client.

Another trivial way to display reports and other file types saved in database in Pivotal Client.

Scenario: display report as PDF file in Pivotal Client by pressing Task Pad item.

Client Task (click event handler):
// Get file content from server
byte[] fileContent = Globals.SystemClient.ExecuteServerTask("Server Task Name", "GetReportContent", new Type[] { typeof(Id) }, new object[] { recordId }) as byte[];

// Create temp file name
string fileName = String.Format("{0}.{1}", Guid.NewGuid(), ".pdf");
string tempFilePath = Path.Combine(System.IO.Path.GetTempPath(), fileName);

using (MemoryStream stream = new MemoryStream(fileContent))
{
 using(FileStream fileStream = new FileStream(tempFilePath, FileMode.Create, System.IO.FileAccess.Write))
 {
  stream.WriteTo(fileStream);
  fileStream.Flush();
  fileStream.Close();
    
  // Open file using windows shell
  Process.Start(tempFilePath);
 }
}
Server Task:
[TaskExecute]
public byte[] GetReportContent(Id recordId)
{
 try
 {
  SystemReport report = this.SystemServer.GetMetaItem<SystemReport>("Report Name") as SystemReport;
  ReportRunner reportRunner = this.SystemServer.CreateReportRunner(report);
  reportRunner.ReportOutputFormat = ReportOutputFormat.Pdf;
  return reportRunner.Run(ReportFilter.SingleRow, recordId, null);
 }
 catch (Exception ex)
 {
  throw new PivotalApplicationCoreException(ex.Message, ex);
 }
}

How to send emails with styles and embedded images using Pivotal API.

A lot of work.
A lot of projects.
But I've got some free time for Pivotal.

Here is an example how to send formatted emails with styles and embedded images via Pivotal API:

Server Task code:
CdcSoftware.Pivotal.Engine.Mail.EmailMessage emailMessage =
   this.SystemServer.CreateMessage();
emailMessage.To.Add("myemail@email.com");
emailMessage.MimeHtmlBodyFileName = @"C:\Email.htm";
emailMessage.Subject = "Test";
emailMessage.Body = "";
emailMessage.Send();

Email.htm file content:
<html>
 <head>
  <style type="text/css">
   body { 
    background-color:Green;
    font-size: 3em;
   }
  </style>
 </head>
<body>
 Test email:
 <img src="image.jpg"/>
</body>
</html>

Of course, you can save html email templates in database, retrieve their content, save as temp file and then use the code above.
Also it is recommended to use SP 10 or later.

Tuesday, March 27, 2012

Using custom grids in Client Forms.

Sometimes we need to build our custom grid to display/manipulate different data.
We can use a standart DataGridView control from System.Windows.Forms.dll, but it doesn't match to Pivotal color scheme.
Therefore there is DataGridViewWithStyle pivotal control in CdcSoftware.Ios.UI.dll that looks like a common Pivotal secondary control.

Here is an example how to use it:

1. Add PivotalCustomControlContainer to a client form
2. Write some client code in form client task:

// Get container control
PivotalCustomControlContainer customGridContainer = this.FormControl.GetControlByName("CustomGridContainer") as PivotalCustomControlContainer;

// Declare custom grid properties and columns
DataGridViewWithStyle customGrid = new DataGridViewWithStyle();
customGrid.Dock = DockStyle.Fill;
customGrid.AllowUserToAddRows = false;
customGrid.AllowUserToDeleteRows = false;
customGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
customGrid.Columns.Add(new DataGridViewTextBoxColumn() { Name = "Id", HeaderText = "Id", Visible = false });
customGrid.Columns.Add(new DataGridViewTextBoxColumn() { Name = "Name", HeaderText = "Name", ReadOnly = true });
customGrid.Columns.Add(new DataGridViewTextBoxColumn() { Name = "Age", HeaderText = "Age", ReadOnly = true });

// Add custom grid to the container
customGridContainer.CustomControl = customGrid;

// Populate grid data
this.PopulateGrid(customGrid);

Thats all.

Regards,
Max Shafranski

Sunday, March 25, 2012

Pivotal CRM 6.0.10 Hot Fix 1 is released.

At last I found free time to blog some good news :)
We got Hot Fix 1 for Pivotal CRM 6.0.10 that brings us many features and bugs fixes.

New features:

  • Pivotal Thin Client support (The most powerful CRM web client).
  • OnFormNavigateAway - form event handler method to execute business logic before navigating away from a form.
  • GetMessageFileWithAttachments - New connector API.

And many bugs were fixed.

Regards,
Max Shafranski

Wednesday, December 21, 2011

What's new in Pivotal CRM 6.0.10?

CDC Software released service pack 10 for Pivotal CRM.

So what's new:

End user features:

  • Drill-down graphs: Users can now double-click on a graph segment to drill-down and get additional information.
  • Tooltips on Graphs.
  • Column personalization support when a Search Results List display is specified: When a search is executed through Client Tasks or through a command with a specified Search Results List display, personalized display for the search is no longer ignored.
  • Optional parameter for Crystal Reports: The optional parameters defined in Crystal Report Designer will now be reflected as optional in the Report Options dialog box while running a report in the Client. Previously these parameters appeared as mandatory in the Report Options dialog box.


Customizers features:

  • Pivotal Visual Workflow 6.0.10.
  • Preselected standard filters: OnStandardFilterLoaded notification was added.
  • Enhancements to Active Search Page: OnSearchResultsListItemClicked notification handler is now fired when a record is clicked on an Active Search Page.
  • External attachment support.
  • Additional Client API to export data in a specified format to a specified destination file: ExportData method.
  • Connector APIs for automated sending of e-mail messages: send e-mail messages automatically without displaying the Outlook inspector window.
  • Additional client-side Connector APIs: Retrieve and Modify.
  • New dialog box for Set Global Options in the Security Business Object.
  • New chart types for Graphs: Line, Column, Doughnut, Point.
  • A Unicode version of the rlangdict.csv file.
  • New fields in E-mail command: To, Cc, Bcc, Subject.
  • Option to open links in a modeless Pivotal Client window.
  • Localization of the Crystal parameter labels.
  • Display open parameters in multiple columns: Open parameters for a search can now be displayed in either a single column or multiple columns.
  • New lightweight SystemProxy proxy class: replacement for PBS XML API.


Administrator features:

  • New user interface with settings to specify form layout display and user authentication during installation.
  • Support for specifying Fully Qualified Domain Name (FQDN) to access ClickOnce deployment servers from different locations.
  • HTTPS support in ClickOnce deployment.
  • Microsoft SQL Server 2008 R2 Native Client support.
  • Improved Pivotal Diagnostics.
  • EMS Inbound Email Address now supports the configuration of the POP3 server port.
  • Enhancements to the Rn1SendX component in Pivotal Business Server to support the configuration of an SMTP port number.
  • SQL Server read-committed snapshot database option.


And of cause, many bugs were fixed.

Thank you,
Max Shafranski

Wednesday, October 26, 2011

CDC Software Pivotal CRM 6.0: How to open window of custom size.

To open forms in popup or modal window we usually use ShowForm method from Foundation Library:

Globals.ShoForm(formOrTableName, recordId, parameterList, actionTargetWindow);


But it opens forms with a default size.
To open forms with the custom size we need to define TargetWindowProperties of the action.

Here is an example:

// Get the instance of ActionService
IActionService actionService = ClientContext.ClientAPIService.GetService();

// Initialize form action target request
IFormActionTarget formActionTarget = actionService.CreateActionTarget();
formActionTarget.Form = "My Form";
formActionTarget.Table = "Support_Incident";            
formActionTarget.RecordId = recordId;
formActionTarget.ParameterList = parameterList;

// Set target window properties
ITargetWindowProperties windowProperties = actionService.CreateNewWindowProperties();
windowProperties.UseDefaultSize = false;
windowProperties.Resizable = true;

// Set the custom window size
windowProperties.Width = 600;
windowProperties.Height = 600;

// Create action to open a popup window
IAction action = actionService.CreateAction(string.Empty, ActionCommand.Show, ActionContent.Record, formActionTarget);
action.TargetWindow = ActionTargetWindow.Popup;
action.TargetWindowProperties = windowProperties;

// Execute action
actionService.ExecuteAction(action);


With the power of Pivotal CRM,
Max Shafranski
:)

Monday, June 27, 2011

Pivotal CRM 6.0.9 is released. What's new?

Good news.

CDC Software released service pack 9 for Pivotal CRM.
Here are the major new features are of Pivotal CRM 6.0.9:

End user features:
  • More flexible and personalizable CRM Task Pane inside Outlook.
  • Default interaction extension for Outlook e-mails, meetings and tasks.
  • Search Standard filter easily identifiable.
  • Improvement in Portal Page Performance.

Customizers features:
  • Microsoft Visual Studio 2010 support and .NET 4
  • New notification OnStandardFilterLoaded is added.
  • A new programming event called the OnBeforeCancelLinks event, has been provided for better programming support with Microsoft Outlook.
  • Support for PIM Client Tasks for e-mail messages.
  • Text wrapping is available for the Search Results List. This can be enabled or disabled by the customizer.
  • Rich text functionality is available for the following: Notes, Search Results Lists, Memo Fields, Primary and Secondary Fields in Forms.
  • Ability to programatically set the Timezone when creating meetings.
  • The maximum number of records returned in the Recipient window is made configurable.
  • Additional Office Integration Server APIs.
  • Client Tasks running inside Outlook do not have to be signed.
  • Pivotal Visual Workflow 6.0.9 (Preview Version)

Administrator features:
  • Support for running multiple distinct applications with multiple Pivotal Business Server instances on the same server.
  • Microsoft Exchange 2010 support.
  • Microsoft SharePoint Server 2010 Standard Edition support.
  • Users can specify the location for the Client Tasks while installing Pivotal Packaged Client.
  • Pivotal Report Driver for Crystal Reports.
  • Custom indexes retained.
  • Visual cue in Pivotal Administration Console to indicate Unicode system.
  • Audit System command available on satellites and mobiles.
  • Changes to the maximum years of expansion for recurring meetings or appointments in Pivotal
  • Synchronization Service for Microsoft Exchange.

Regards,
Max Shafranski

Monday, May 2, 2011

CDC Software Pivotal CRM 6.0: View table fields audit log SQL query.

If a field marked as "Monitor on Log" then any its changes will be save in Pivotal history table.

This SQL script helps Pivotal developers to view a field change log details:

DECLARE
 @Table_Name nvarchar(28),
 @Table_Id binary(8),
 @Record_Id binary(8)

--Set input parameters
SET @Table_Name = 'Support_Incident'
SET @Record_Id = 0x8000000000000088

--Get table ID from BM database
SELECT @Table_Id = Tables_Id FROM PivotalBM.dbo.Tables WHERE Table_Name = @Table_Name

--Select audit entries for the required record from ED database
SELECT
    Journal_History.Field_Label,
    Journal_History.New_Value,
    Journal_History.Time_Stamp,
    Employee.Full_Name AS [Employee_Name]
FROM PivotalED.dbo.Journal_Items
INNER JOIN Journal_Pages ON Journal_Pages.Journal_Pages_Id = Journal_Items.Journal_Pages_Id
INNER JOIN Journal_History ON Journal_History.Journal_Pages_Id = Journal_Pages.Journal_Pages_Id
INNER JOIN Employee ON Journal_History.Rn_Create_User=Employee.Rn_Employee_User_Id
WHERE Journal_Items.Reference_Table = @Table_Id AND Journal_Items.Reference_Record = @Record_Id
ORDER BY Journal_History.Time_Stamp DESC

CRM it is no joke!

Thursday, March 17, 2011

CDC Software Pivotal CRM 6.0: How to change form title programmatically.

It's not easy as I thought.

I need to change a new form title that always set to "New".
And I don't want to change language strings and add parameters like "My new %1"...

FormView.FormTitle is read only property.
Also, FormView class marked as internal class that implements IFormView interface.
So, we can't access directly to to the internal class from another assembly.
But there is a nice solution that always works - Reflection.

 public override void OnFormInitialized()
{
  //Get user defined form title
  string userDefinedFormTitle = Convert.ToString(this.FormControl.WindowsControl.GetType().GetProperty("FormTitle").GetValue(this.FormControl.WindowsControl, null));

            
  //Set new form title
  this.FormView.GetType().GetProperty("FormTitle").SetValue(this.FormView, originalFormTitle, null);
 }


Reflection rules!
Max

Thursday, February 10, 2011

ASP.NET MVC: Disable submit button after click when using Microsoft MVC client validation library.

If you want to disable submit button after it has been clicked you can use this jQuery code:

$("form").bind("submit", function (e) {
   // On submit disable form submit button
   $('input[type=submit]', this).attr('disabled', 'disabled');
});

But if you use MVC client validation

<% Html.EnableClientValidation(); %>

and the form has validation errors, the submit button will be disabled anyway.

So, we need to modify our submit form handler function to check if the form has errors.

$("form").bind("submit", function (e) {
   var mvcValidationContext = e.srcElement['__MVC_FormValidation'];
   if (mvcValidationContext) {
      var formValidationErrorsCount = mvcValidationContext.validate('submit').length;
      if (formValidationErrorsCount == 0) {
         // On submit disable form submit button
         $('input[type=submit]', this).attr('disabled', 'disabled');
      }
   }
});

Thats all.

Sunday, January 2, 2011

CDC Software Pivotal CRM 6.0: How to change rows style in PivotalSearchResultGrid

Here is an example we can access to PivotalSearchResultsGrid rows.
Lets color all rows that contain specific Company_Name value.
First of all we need to add DataBindingComplete event handler to the PivotalSearchResultsGrid control.
To do it we need to override OnFormInitialized method that fires after the form has been drawn and all the data has been loaded and bound:

public override void OnFormInitialized()
{
    PivotalSearchResultsGrid mySearchResultsGrid =   this.FormControl.GetControlByName("CompaniesPivotalSearchResultsGrid") as PivotalSearchResultsGrid;
    if (mySearchResultsGrid != null)
    {
        //Get a grid control from the PivotalSearchResultsGrid
        DataGridView grid = mySearchResultsGrid.ResultsViewControl.Controls[0].Controls[0] as DataGridView;
        //Handle DataBindingComplete event that fires when the content DataSource changed
        grid.d.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dataGridView1_DataBindingComplete);
    }
}

Than just implement the dataGridView1_DataBindingComplete event handler:

private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    DataGridView grid = sender as DataGridView;
    for (int i = 0; i < grid.Rows.Count; i++ )
    {
        DataGridViewRow row = grid.Rows[i];
        //Access to row data
        string companyName = row.Cells["Company_Name"].Value.ToString();
        if (companyName == "Microsoft")
        {
            //Paint row in Blue
            row.DefaultCellStyle.BackColor = Color.Blue;
        }
    }
}

Thats all.
Enjoy with Pivotal 6.0.

Saturday, January 1, 2011

CDC Software Pivotal 6.0: How to prevent to open record on double click in PivotalSearchResultsGrid control.



This is the way to remove an original CellMouseDoubleClick event handler to prevent to open records on double click in PivotalSearchResultsGrid.


Add CdcSoftware.Ios.dll reference to you Client Task project. 
Add DisableSearchResultGridDoubleClick function call in your Client Task in OnFormInitialized handler:


public override void OnFormInitialized()
{
 PivotalSearchResultsGrid clientDetectionSearchResultsGrid = this.FormControl.GetControlByName("ClientDetectionPivotalSearchResultsGrid") as PivotalSearchResultsGrid;
 if (clientDetectionSearchResultsGrid != null)
 {
  DisableSearchResultGridDoubleClick(clientDetectionSearchResultsGrid);
 }
}

private void DisableSearchResultGridDoubleClick(PivotalSearchResultsGrid grid)
{
 if (grid != null)
        {
         FieldInfo eventHandlerInfo = grid.ResultsViewControl.GetType().GetField("CellMouseDoubleClick", BindingFlags.NonPublic | BindingFlags.Instance);
                object oHandler = eventHandlerInfo.GetValue(grid.ResultsViewControl);

                EventHandler<cdcsoftware.iaf.ios.messaging.iafmessageeventargs> eventHandler = oHandler as EventHandler<cdcsoftware.iaf.ios.messaging.iafmessageeventargs>;

                if (eventHandler != null)
                {
                    grid.ResultsViewControl.CellMouseDoubleClick -= eventHandler;
                }
            }
        }
}

Monday, December 13, 2010

CDC Software Pivotal CRM 6.0: How to pass parameters from one client form to another.

This is a code example that describes how to pass parameters to another form.

Code example: open form B and send custom parameters from form A

//Form A:

TransitionPointParameter transitionParam = new TransitionPointParameter();
//Custom parameters (1 based index)
transitionParam.SetUserDefinedParameter(1, "Hello");
transitionParam.SetUserDefinedParameter(2, 123);

//Auto mapped parameters
transitionParam.AddDefaultColumn("First_Name", "Bobo");

ParameterList parameterList = (ParameterList)transitionParam.Construct();

//Open Form B and pass parameters
Globals.ShowForm("Company", null, parameterList);

//Form B:

//Close caller record
if (this.TransitionPointParameter.UserDefinedParametersNumber > 0)
{
    string message = (string)this.TransitionPointParameter.GetUserDefinedParameter(1);
    int number = (int)this.TransitionPointParameter.GetUserDefinedParameter(2);
}

Thursday, December 2, 2010

MS CRM 4.0: How to hide IFRAME padding in CRM forms

This is the way to remove iframe padding programmatically.
Add setIFrameSource function to your crm form OnLoad event.


function onCrmFormLoaded() {
 // ...

 //Display related records in iframe
 setIFrameSource();
 
 // ...
}

function setIFrameSource() {
 if (crmForm.ObjectId) {
  // Generate url to display related records
  var url = 'areas.aspx?oId=' + crmForm.ObjectId + '&oType=10000&security=852023&tabSet=new_new_myentity=entityA_new_entityB';
  // Set iframe source
  crmForm.all.IFRAME_entity.src = url;
  // Remove padding when iframe is loaded
  crmForm.all.IFRAME_entity.attachEvent('onreadystatechange', onIFrameReady);
 }
 else {
  // Hide iframe
  crmForm.all.IFRAME_entity.parentElement.parentElement.style.display = 'none';
 }
}

function onIFrameReady(e) {
 if (e.srcElement.readyState == 'complete') {
  var doc = e.srcElement.contentWindow.document;
  // Remove scrolling space
  doc.body.scroll = "no";
  // Remove crmGrid default padding
  doc.body.childNodes[0].rows[0].cells[0].style.padding = 0;
 }
}