This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UIX - getting property values from selected item

I am relatively new to using UIX and am wondering if there is any way that I can get the property values for the selected item within m-files.

An example of what we are trying to do is basically, when you select a person we are using UIX to display certain information about the person selected in a more user friendly format. So far we have run into difficulty with how we can retrieve/display specific properties from the person selected.

Can anyone help with any code on how we can achieve this?

  • The below is an answer for this running on the M-Files Desktop interface.  If you're running on the web then the answer is more awkward.  I guess you're not, though, so I hope this is useful.

    When you react to the selection being changed, you'll be provided with an instance of IShellItems.  That has properties on it that allows you to easily get information about what was selected.

    One of those properties is ObjectVersionsAndProperties, which is an instance of ObjectVersionAndPropertiesOfMultipleObjects in the COM API (yes, I know some of these class names are verbose!).

    That instance should allow you to access the property data without having to go back to the vault to load it.

  • Hello Craig
    Thank you so much for this answer. By any chance do you have examples that we can see because we cannot figure out the way that the code you have provided is implemented? An example will help us figure out how the code is applied.

  • Not that does exactly what you want, but this example reacts to items being selected: MFilesSamplesAndLibraries/Samples/UIX Applications/OpenExternalApplicationOnCommand/main.js at master · M-Files/MFilesSamplesAndLibraries (github.com)

    You'd alter this around line 100 to instead read the data from the selected items, then do whatever you want to do with it.

  • I am not to well versed in programming UIX and keep getting 'undefined' returned to me. We already had selectedItems.objectversions(0) which would return the title, guid, etc. Then when I changed this to selectedItems.objectversionsandproperties(0) it starts returning undefined items. I do not know if this is because the shellui code is incorrect or if i am not referencing the properties correctly within the js file?

  • Can you show your actual module code?

  • shellui.js

     return function (shellListing) {
                // Listen for selection change events on the listing
                shellListing.Events.Register(
                    Event_SelectionChanged,
                    function (selectedItems) {
                        // We may get many events raised; only deal with the active listing.
                        if (false == shellListing.IsActive) {
                            return;
                        }
    
    
    
                        // Sanity.
                        if (null == commandId) {
                            return;
                        }
    
                        var name1 = shellListing.selectedItems.ObjectVersions;
                        alert('this is the result: ' + name1)
                        // There may be no point enabling our button if the user hasn't selected any objects we want to process.
                        // For now, just assume they have (button is available always).
                        var commandViable = true;
    
    
    
                        // If the command is viable then enable the buttons.
                        if (commandViable) {
                            // Show the command everywhere (affects both context menu and task pane).
                            // ref: http://www.m-files.com/UI_Extensibility_Framework/index.html#MFClientScript~ICommands~SetCommandState.html
                            shellFrame.Commands.SetCommandState(commandId, CommandLocation_All, CommandState_Active);
                        }
                        else {
                            // Hide the command everywhere (affects both context menu and task pane).
                            // ref: http://www.m-files.com/UI_Extensibility_Framework/index.html#MFClientScript~ICommands~SetCommandState.html
                            shellFrame.Commands.SetCommandState(commandId, CommandLocation_All, CommandState_Hidden);
                        }
                    });

    my-dashboard.js

        // Some things are ready only after the dashboard has started.
        dashboard.Events.Register(MFiles.Event.Started, OnStarted);
        function OnStarted() {
    
            // Get the object version from the custom data passed from shell ui part.
            var objectVersion = dashboard.CustomData.ObjectVersion;
    
       
           // var propFullName = Vault.ObjectPropertyOperations.GetProperty(ObjVer, Property.propFullName.Id);
        
    
           // var IDS = GetIDsByAliases();
    
            //AppendBodyWithParagraph("Document Guid: " + propFullName);
            // AppendBodyWithParagraph("Document 1: " + GetIDsByAliases().Property.propFullName.Id);
            //AppendBodyWithParagraph("Document 1 " + objectVersion.CustomData.);
            //AppendBodyWithParagraph("Document 2 " + Property.propFullName.Id);
            //AppendBodyWithParagraph("Document 3 " + Property.propFullName.Id.Name);
    
            // Show some information of the document.
            AppendBodyWithParagraph("Document Title: " + objectVersion.Title);
            AppendBodyWithParagraph("Document Internal Id: " + objectVersion.ObjVer.ID);
            AppendBodyWithParagraph("Document Guid: " + objectVersion.ObjectGUID);
            AppendBodyWithParagraph("Document Version: " + objectVersion.ObjVer.Version);
            AppendBodyWithParagraph("Document Version Guid: " + objectVersion.VersionGUID);
            AppendBodyWithParagraph("Document employee name: " + objectVersion.propFullName.ID);
    
        }

  • So forget the dashboard for the moment.

    • You cannot use "alert" in module code.  It doesn't have a window context; it's run within Windows Scripting Host.  You have to use "shellFrame.ShowMessage()" instead.

    • What in this returns null?  I assume that shellListing.selectedItems.ObjectVersionsAndProperties isn't null.

    Can you do this?

    var name1 = shellListing.selectedItems.ObjectVersionsAndProperties[0].VersionData.Name
    shellFrame.ShowMessage('this is the result: ' + name1);

  • sorry forgot this part from the shellui.js

        // 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", "Employee Summary", "_last");
        }
    
        // 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) {
    
            // Show, if exactly one document is selected, otherwise hide.
            if (IsExactlyOneDocumentSelected(selectedItems) || IsLighticoClientSelected(selectedItems))
                ShowDashboard(selectedItems.ObjectVersions[0]);
            else
                HideDashboard();
        }

    Additionally when i change the above code from selecteditems.objectversions[0] to selecteditems.objectversionsandproperties[0] then these start giving me back undefined
    " AppendBodyWithParagraph("Document Title: " + objectVersion.Title);
    AppendBodyWithParagraph("Document Internal Id: " + objectVersion.ObjVer.ID);
    AppendBodyWithParagraph("Document Guid: " + objectVersion.ObjectGUID);
    AppendBodyWithParagraph("Document Version: " + objectVersion.ObjVer.Version);
    AppendBodyWithParagraph("Document Version Guid: " + objectVersion.VersionGUID);
    AppendBodyWithParagraph("Document employee name: " + objectVersion.propFullName.ID);"

  • That's because "selectedItems.ObjectVersionsAndProperties[0]" returns one of these, which doesn't have any of those properties.  You want to do "selectedItems.ObjectVersionsAndProperties[0].VersionData" to get the same properties.

  • Ok it is no longer returning undefined for everything to do with the guid and version. What value will I have to insert into this in order to get back the specific property within the item selected because that is still being sent back as undefined?