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?

Parents Reply
  • 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?

Children
  • 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?

  • The ObjectVersionAndProperties instance also has a property named "Properties" which is effectively a collection you can use to retrieve the object's metadata.  You would need to use the appropriate methods on that to retrieve the information you need.

  • Ok so if I use ObjectVersionAndProperties how would get the string from a specific property. would I use the ID of the property or the alias?

  • How would you do it without ObjectVersionAndProperties?

    var objectVersionAndProperties = selectedItems.ObjectVersionAndProperties[0];
    var objectVersion = objectVersionAndProperties.VersionData;
    var properties = objectVersionAndProperties.Properties;
    
    // Now work with the available information that the properties class exposes,
    // ref: https://developer.m-files.com/APIs/COM-API/Reference/#MFilesAPI~PropertyValues.html
    
    var nameOrTitlePropertyValue = getPropertyValueById(properties, 0);
    if(null != nameOrTitlePropertyValue)
    {
      shellFrame.ShowMessage("Object is named: " + nameOrTitlePropertyValue.GetValueAsLocalizedText());
    }
    
    var classPropertyValue = getPropertyValueById(properties, 100);
    if(null != classPropertyValue)
    {
      shellFrame.ShowMessage("Object is in class: " + classPropertyValue.GetValueAsLocalizedText());
    }
    
    // Some helpers.
    function getPropertyValueById(pv, id)
    {
      var index = pv.IndexOf(id);
      if(index == -1)
        return null;
      return pv[index];
    }
    function getPropertyValueByAlias(pv, alias)
    {
      var index = pv.IndexOfByAlias(id);
      if(index == -1)
        return null;
      return pv[index];
    }

  • Thankyou so much. We have gotten the results we were looking for