Custom Dashboard - Custom Data & Object Display

Hi,

I am using an activex object to create custom data for my dashboard using sql. It looks like you cannot return an adodb recordset as the data source. Should I be creating JSON from the adodb.recordset? I am assuming that in order to access the data properly and be able to filter the data and parse through it that it will need to be in a JSON format. Is this assumption correct? 

I also want to only display this dashboard tab when someone has selected a "SalesOrder" object within M-Files. I'm not quite sure how to do this.

Below is my js code thus far with the connection string replaced with ""

"use strict";
  
function OnNewShellUI( shellUI )
{	
	// Register to be notified when a new normal shell frame (Event_NewNormalShellFrame) is created.
	// We use Event_NewNormalShellFrame rather than Event_NewShellFrame as this won't fire for history (etc.) dialogs.
	shellUI.Events.Register(
		Event_NewNormalShellFrame,
		handleNewShellFrame );
}
 

function handleNewShellFrame(shellFrame)
{
 
	// Register to be notified when the shell frame is started.
	// This time pass a reference to the function to call when the event is fired.
	shellFrame.Events.Register(
		Event_Started,
		getShellFrameStartedHandler( shellFrame) );
}

function getCustomData() {
    //database connection
    var connection = new ActiveXObject("ADODB.Connection");
    var connectionstring = "";
    connection.Open(connectionstring);

    var rs = new ActiveXObject("ADODB.Recordset");
    var results = '';

    rs.Open("SELECT top 10 * FROM SalesOrders", connection);
    rs.MoveFirst;

    //move through recordset. Create JSON?
    while (!rs.eof) {
        results = results + ' ' + rs.fields(0).value.toString();
        rs.movenext;
    }

    rs.close;
    connection.close;

    return results;
}
 
function getShellFrameStartedHandler(shellFrame)
{
	/// <summary>Returns a function which handles the OnStarted event for an IShellFrame.</summary>
    // This is the ID of the dashboard, as declared in the appdef.xml file.
    var dashboardId = "soDashboard";
 
    var customData = getCustomData()
    
	return function() {
		// The shell frame is now started and can be used.
		
		var tab = shellFrame.RightPane.AddTab( "mySalesOrderDashboard", "SO Details", "_last" );
 
		// Load the content into the tab.
		tab.ShowDashboard( dashboardId, customData );
        // Show the tab.
		tab.visible = true;
        // Register to be notified when new shell listings are created.
		shellFrame.Events.Register(
			Event_NewShellListing,
			getNewShellListingHandler( shellFrame, tab ) );

		// Is there already a listing?  If so then we need to hook into it as well.
		if (null != shellFrame.Listing)
		{
			getNewShellListingHandler( shellFrame, tab, dashboardId )( shellFrame.Listing );
		}
	}

    function getNewShellListingHandler(shellFrame, tab, dashboardId)
{
	/// <summary>Gets a function to handle the NewShellListing event for shell frame.</summary>
	/// <param name="shellFrame" type="MFiles.ShellFrame">The current shell frame object.</param> 
	/// <returns type="MFiles.Events.OnNewShellListing">The event handler.</returns>

	// Return the handler function for NewShellListing event.
	return function(shellListing)
	{
		// Listen for selection change events on the listing.
		shellListing.Events.Register(
			Event_SelectionChanged,
			function(selectedItems)
			{
				// Sanity.
				if (false == shellListing.IsActive)
				{
					return false;
				}

				// Show our dashboard.
				tab.ShowDashboard(dashboardId, selectedItems);

				// We succeeded; return true.
				return true;
			} );
	};
}
}

Parents
  • I was able to get this to work using the following code. I'm not sure if the way I went about this is the best way to do it. Let me know if should be going about this a different way.

        function getNewShellListingHandler(shellFrame, tab, dashboardId)
    {
    	/// <summary>Gets a function to handle the NewShellListing event for shell frame.</summary>
    	/// <param name="shellFrame" type="MFiles.ShellFrame">The current shell frame object.</param> 
    	/// <returns type="MFiles.Events.OnNewShellListing">The event handler.</returns>
    
    	// Return the handler function for NewShellListing event.
    	return function(shellListing, selectedItems)
    	{
    		
         	// Listen for selection change events on the listing.
    		shellListing.Events.Register(
    			Event_SelectionChanged,
    			function(selectedItems)
    			{
    				// Sanity.
    				if (false == shellListing.IsActive)
    				{
    					return false;
    				}
                    var salesOrder = selectedItems.ObjectVersionsAndProperties;
                    var salesOrder2 = ''
                    var salesOrderId = ''
                    var customData = {}//getCustomData()
            
                    if (selectedItems.Count == 1) {
            
                        var  isObjSalesOrder = (selectedItems.ObjectVersions.Count === 0 ? '' : selectedItems.ObjectVersionsAndProperties.Item(1).ObjVer.ObjID.Type);
            
            
                        salesOrder2 = (isObjSalesOrder === 332 ? (salesOrder2 == '' ? (salesOrder.Item(1).Properties.SearchForProperty(0).Value.DisplayValue) : 
                        (salesOrder.Item(1).Properties.SearchForProperty(0).Value.DisplayValue)) : '')
    
                    }
                    
                    if (isObjSalesOrder !== 332) {
    
                        tab.visible = false;
                        return false;
    
                    } else {
                        salesOrderId = salesOrder2.split("_")
                        customData = getCustomData(salesOrderId[0]);
                        // Show our dashboard.
                        tab.ShowDashboard(dashboardId, customData);
                         // Show the tab.
                        tab.visible = true;
        
                        // We succeeded; return true.
                        return true;
    
                    }
            
    			} );
    	};
    }

  • Hello,

    This is my code for showing a tab.

    function OnNewNormalShellFrame(shellFrame) {
        // Add tab to right pane, when the shell frame is started.
        var myTab;
        shellFrame.Events.Register(MFiles.Event.Started, OnStarted);
        function OnStarted() {
            myTab = shellFrame.RightPane.AddTab("my-tab", "Service Suport", "_last");
            myTab.Unselect();
        }
        // React to when the selection changes in the ui.
        shellFrame.Events.Register(MFiles.Event.NewShellListing, OnNewShellListing);
        function OnNewShellListing(shellListing) {
            shellListing.Events.Register(MFiles.Event.SelectionChanged, OnSelectionChanged);
        }
        // Show dashboard, if exactly one document is selected.
        function OnSelectionChanged(selectedItems) {
    		if(selectedItems.ObjectVersions.Count != 1)
                return;
            var item = selectedItems.ObjectVersions[0];
            var itemclassfull = shellFrame.ShellUI.Vault.ObjectPropertyOperations.GetProperty(item.ObjVer, 100).TypedValue.DisplayValue;
            var ServiceIDsearch = shellFrame.ShellUI.Vault.ObjectPropertyOperations.GetProperty(item.ObjVer, 4562).TypedValue.DisplayValue;
            if (itemclassfull == "Service Suport" && IsExactlyOneDocumentSelected(selectedItems) && Number(ServiceIDsearch) < 820) {
    			
    			
                ShowDashboard(ServiceIDsearch);
            }
            
            
            else {
                HideDashboard();
            }
            myTab.Unselect();
        }
        // Returns true, if exactly one document is selected.
        function IsExactlyOneDocumentSelected(selectedItems) {
            // Ensure that we have exactly one item selected and that it is an object.
            if (selectedItems.Count != 1 || selectedItems.ObjectVersions.Count != 1) {
                return false;
            }
            // Exactly one document is selected.
            return true;
        }
        // Shows dashboard in the tab and sets the tab visible.
        function ShowDashboard(ServiceID) {
            // Show dashboard content in right pane tab. Ensure that the tab is visible.
            myTab.ShowDashboard("ServiceSuport", ServiceID);
            myTab.Visible = true;
        }
        // Hides the dashboard by hiding the tab.
        function HideDashboard() {
            // Ensure that the tab is not visible.
            myTab.Visible = false;
        }
    }

Reply
  • Hello,

    This is my code for showing a tab.

    function OnNewNormalShellFrame(shellFrame) {
        // Add tab to right pane, when the shell frame is started.
        var myTab;
        shellFrame.Events.Register(MFiles.Event.Started, OnStarted);
        function OnStarted() {
            myTab = shellFrame.RightPane.AddTab("my-tab", "Service Suport", "_last");
            myTab.Unselect();
        }
        // React to when the selection changes in the ui.
        shellFrame.Events.Register(MFiles.Event.NewShellListing, OnNewShellListing);
        function OnNewShellListing(shellListing) {
            shellListing.Events.Register(MFiles.Event.SelectionChanged, OnSelectionChanged);
        }
        // Show dashboard, if exactly one document is selected.
        function OnSelectionChanged(selectedItems) {
    		if(selectedItems.ObjectVersions.Count != 1)
                return;
            var item = selectedItems.ObjectVersions[0];
            var itemclassfull = shellFrame.ShellUI.Vault.ObjectPropertyOperations.GetProperty(item.ObjVer, 100).TypedValue.DisplayValue;
            var ServiceIDsearch = shellFrame.ShellUI.Vault.ObjectPropertyOperations.GetProperty(item.ObjVer, 4562).TypedValue.DisplayValue;
            if (itemclassfull == "Service Suport" && IsExactlyOneDocumentSelected(selectedItems) && Number(ServiceIDsearch) < 820) {
    			
    			
                ShowDashboard(ServiceIDsearch);
            }
            
            
            else {
                HideDashboard();
            }
            myTab.Unselect();
        }
        // Returns true, if exactly one document is selected.
        function IsExactlyOneDocumentSelected(selectedItems) {
            // Ensure that we have exactly one item selected and that it is an object.
            if (selectedItems.Count != 1 || selectedItems.ObjectVersions.Count != 1) {
                return false;
            }
            // Exactly one document is selected.
            return true;
        }
        // Shows dashboard in the tab and sets the tab visible.
        function ShowDashboard(ServiceID) {
            // Show dashboard content in right pane tab. Ensure that the tab is visible.
            myTab.ShowDashboard("ServiceSuport", ServiceID);
            myTab.Visible = true;
        }
        // Hides the dashboard by hiding the tab.
        function HideDashboard() {
            // Ensure that the tab is not visible.
            myTab.Visible = false;
        }
    }

Children
No Data