Hi,
I'm loading quite a bit of data from value lists when starting my dashboard, which causes a slight delay and can have an impact on users. The way around this would be to use search conditions within the main.js file to really filter down the results that I am getting. I can't seem to figure out how to properly reference M-Files API to create search conditions. Can anyone guide me in the right direction as to how to use M-Files search conditions within the main.js file. Review the code. You can see some commented out attempts at my search conditions
"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(type, shellFrame, selectedItems, ObjVer) { //database connection var oVault = shellFrame.ShellUI.Vault var item = selectedItems.ObjectVersions[0] var organizationsValueList = oVault.ValueListItemOperations.GetValueListItems(347) var organizationLocationsValueList = oVault.ValueListItemOperations.GetValueListItems(337) var contactPersonValueList = oVault.ValueListItemOperations.GetValueListItems(320) var shippingMethodValueList = oVault.ValueListItemOperations.GetValueListItems(358) var shipPaymentTypeValueList = oVault.ValueListItemOperations.GetValueListItems(388) var paymentTermValueList = oVault.ValueListItemOperations.GetValueListItems(368) var salesPersonValueList = oVault.ValueListItemOperations.GetValueListItems(465) var taxCodeValueList = oVault.ValueListItemOperations.GetValueListItems(395) var partRevisionValueList = oVault.ValueListItemOperations.GetValueListItems(329) var partValueList = oVault.ValueListItemOperations.GetValueListItems(328) var orgFreightDiscount = 0 var currentOrganization = '"currentOrganization": [{"label": "", "value": "", id ""}],' var currentContactPerson = '"currentContactPerson": [{"label": "", "value": ""}]' // var oObjectID = MFilesAPI.ObjVer.Objid.ID /*var oSearchCondition = MFilesAPI.searhConditions var oSearchConditions = new MFilesAPI.searchCondition oSearchCondition.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual oSearchCondition.Expression.DataStatusValueType = MFStatusTypeObjectID oSearchCondition.TypedValue.SetValue(MFDatatypeText, oVault.ObjectPropertyOperations.GetProperty(selectedItems.ObjectVersionsAndProperties.Item(1).ObjVer, 2072).value.DisplayValue ) oSearchConditions.Add( -1, oSearchCondition) oSearchCondition.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual oSearchCondition.Expression.Type = 5 oSearchCondition.TypedValue.SetValue(MFDatatypeLookup, oVault.ObjectPropertyOperations.GetProperty(selectedItems.ObjectVersionsAndProperties.Item(1).ObjVer, 2072).value.DisplayValue ) oSearchCondition.TypedValue.SetValue(MFDatatypeLookup, oVault.ObjectPropertyOperations.GetProperty(selectedItems.ObjectVersionsAndProperties.Item(1).ObjVer, 2072).value.DisplayValue )*/ if (type == 347) { currentOrganization = '{"currentOrganization": [{"label": "' + oVault.ObjectPropertyOperations.GetProperty(ObjVer, 2072).value.DisplayValue + '", "value": "' + oVault.ObjectPropertyOperations.GetProperty(ObjVer, 2006).value.DisplayValue + '", "id": "' + ObjVer.ObjId.ID + '"}],' } else if (type == 320) { currentContactPerson = ' "currentContactPerson": [{"label": "' + oVault.ObjectPropertyOperations.GetProperty(ObjVer, 2485).value.DisplayValue + '", "value": "' + oVault.ObjectPropertyOperations.GetProperty(ObjVer, 2485).value.value +'"}]' currentOrganization = '{"currentOrganization": [{"label": "' + oVault.ObjectPropertyOperations.GetProperty(ObjVer, 2072).value.DisplayValue + '", "value": "' + oVault.ObjectPropertyOperations.GetProperty(ObjVer, 2006).value.DisplayValue +'"}],' } else if (type == 386) { } var results = currentOrganization + currentContactPerson + ', "organizations": [{' for (var i = 1; i < organizationsValueList.Count + 1; i++) { results = results + '"label": "' + organizationsValueList.item(i).Name + '", "value": "' + organizationsValueList.item(i).DisplayID + '", "id": "' + organizationLocationsValueList.item(i).ID + '"}' if (i === organizationsValueList.Count){ results = results + '], "organizationLocations": [{' } else { results = results + ',{' } }; for (var i = 1; i < organizationLocationsValueList.Count + 1; i++) { results = results + '"label": "' + organizationLocationsValueList.item(i).Name + '", "value": "' + organizationLocationsValueList.item(i).DisplayID + '", "owner": "' + organizationLocationsValueList.item(i).OwnerID + '"}' if (i === organizationLocationsValueList.Count){ results = results + '], "contactPersons": [{' } else { results = results + ',{' } }; for (var i = 1; i < contactPersonValueList.Count + 1; i++) { results = results + '"label": "' + contactPersonValueList.item(i).Name + '", "value": "' + contactPersonValueList.item(i).DisplayID + '"}' if (i === contactPersonValueList.Count){ results = results + '], "shippingMethods": [{' } else { results = results + ',{' } }; for (i = 1; i < shippingMethodValueList.count + 1; i++) { results = results + ' "label": "' + shippingMethodValueList.item(i).Name + '", "value": "' + shippingMethodValueList.item(i).DisplayID + '"}' if (i === shippingMethodValueList.Count){ results = results + '], "shipPaymentTypes": [{' } else { results = results + ',{' } } for (i = 1; i < shipPaymentTypeValueList.count + 1; i++) { results = results + ' "label": "' + shipPaymentTypeValueList.item(i).Name + '", "value": "' + shipPaymentTypeValueList.item(i).DisplayID + '"}' if (i === shipPaymentTypeValueList.Count){ results = results + '], "paymentTerms": [{' } else { results = results + ',{' } } for (i = 1; i < paymentTermValueList.count + 1; i++) { results = results + ' "label": "' + paymentTermValueList.item(i).Name + '", "value": "' + paymentTermValueList.item(i).DisplayID + '"}' if (i === paymentTermValueList.Count){ results = results + '], "salesPersons": [{' } else { results = results + ',{' } } for (i = 1; i < salesPersonValueList.count + 1; i++) { results = results + ' "label": "' + salesPersonValueList.item(i).Name + '", "value": "' + salesPersonValueList.item(i).DisplayID + '"}' if (i === salesPersonValueList.Count){ results = results + '], "parts": [{' } else { results = results + ',{' } } for (i = 1; i < partValueList.count + 1; i++) { results = results + ' "label": "' + partValueList.item(i).Name.replace(/\"/g, '\\\"') + '", "value": "' + partValueList.item(i).DisplayID + '"}' if (i === partValueList.Count){ results = results + '], "partRevisions": [{' } else { results = results + ',{' } } for (i = 1; i < partRevisionValueList.count + 1; i++) { results = results + ' "label": "' + partRevisionValueList.item(i).Name.replace(/\"/g, '\\\"') + '", "value": "' + partRevisionValueList.item(i).DisplayID + '"}' if (i === partRevisionValueList.Count){ results = results + '], "taxCodes": [{' } else { results = results + ',{' } } for (i = 1; i < taxCodeValueList.count + 1; i++) { results = results + ' "label": "' + taxCodeValueList.item(i).Name + '", "value": "' + taxCodeValueList.item(i).DisplayID + '"}' if (i === taxCodeValueList.Count){ results = results + ']}' } else { results = results + ',{' } } String.prototype.escapeSpecialChars = function() { return this.replace(/\\&/g, "\\&") .replace(/\\r/g, "\\r") .replace(/\\t/g, "\\t") .replace(/\\b/g, "\\b") .replace(/\\f/g, "\\f") .replace(/\\n/g, "\\n") .replace(/\“/g, "\“") .replace(/\”/g, "\”") .replace(/^[\u0080-\uffff]/g, "") .replace(/^[\u0000-\u001f]/g, "") .replace(/ä/g, "a") .replace(/ö/g, "o") .replace(/Ä/g, "A") .replace(/Ö/g, "O") .replace(/\&/g, "\&") .replace(/\#/g, "\#") .replace(/\(/g,'\(') .replace(/\)/g,'\)') .replace(/\//g,'\/') .replace(/\{/g,'\{') .replace(/\}/g,'\}') .replace(/[\t\r\n]/g, '') }; return results.escapeSpecialChars(); } function getCurrentQuoteData(shellFrame, selectedItems) { return true } 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 = "quoteBuilder"; return function() { // The shell frame is now started and can be used. var tab = shellFrame.RightPane.AddTab( "quoteBuilder", "Quote Builder", "_last" ); // Register to be notified when new shell listings are created. shellFrame.Events.Register( Event_NewShellListing, getNewShellListingHandler( shellFrame, tab, dashboardId ) ); // 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, selectedItems) { // Listen for selection change events on the listing. shellListing.Events.Register( Event_SelectionChanged, function(selectedItems) { // Sanity. if (false == shellListing.IsActive) { return false; } var obj = selectedItems.ObjectVersionsAndProperties; var customData = []; if (selectedItems.Count == 1) { var objType = (selectedItems.ObjectVersions.Count === 0 ? '' : obj.Item(1).ObjVer.ObjID.Type); } if (objType == 347) { value = obj.Item(1).Properties.SearchForProperty(2072).Value.DisplayValue customData = getCustomData(obj.Item(1).ObjVer.ObjID.Type, shellFrame, selectedItems, obj.Item(1).ObjVer); // try { tab.ShowDashboard(dashboardId, customData); // Show the tab. tab.visible = true; shellFrame.RightPane.GetTab('_details').Select() return true; /* } catch(e) { tab.visible = false; return false; }*/ } else if (objType == 320) { customData = getCustomData(obj.Item(1).ObjVer.ObjID.Type, shellFrame, selectedItems, obj.Item(1).ObjVer); try { tab.ShowDashboard(dashboardId, customData, objType); // Show the tab. tab.visible = true; shellFrame.RightPane.GetTab('_details').Select() return true; } catch(e) { tab.visible = false; return false; } } else if (objType == 386) { customData = getCustomData(obj.Item(1).ObjVer.ObjID.Type, shellFrame, selectedItems); try { tab.ShowDashboard(dashboardId, customData, objType); // Show the tab. tab.visible = true; return true; } catch(e) { tab.visible = false; return false; } } else { tab.visible = false; return false; } } ); }; } }