Portal Asset Search

IT MonkeyIT Monkey O.G.
edited March 6 in Cireson Uploads
We've updated this code and turned it into a Github repository to promote community contribution! See the Github announcement in the discussions section for instructions on how to do this!

https://github.com/Cireson/Community_PortalAssetSearch.git

Hardware Asset Search

Instructions:
Copy the code in custom_HardwareAssetSearch.js , and place it anywhere in your customspace folder. Alternatively, copy the file and place it into your customspace directory, and then add the following line to your custom.js file:
$.getScript("/CustomSpace/custom_HardwareAssetSearch.js");

Purpose:
After this script is in place, it will add an input box within the Hardware Asset navigation node on the left, which allows a very fast dynamic search of hardware assets by Display Name. 

Tips and tricks
1. You can use an automated process (scorch, workflow) to change the display name of all assets to include a serial number or asset tag. Then, this search will also natively search those fields too.
2. This input box does follow navigation node permissions, but it will also only appear if the user is in the AssetManager AD group, or is an SCSM admin. 
3. This script looks for the header "Hardware Assets". If you have modified this navigation node, then you will need to adjust the script accordingly.
«13

Comments

  • Ian_GlennIan_Glenn Member IT Monkey ✭
    I implemented this in my environment and when I search I am getting two results returned for each Asset; and when I click on the asset I randomly get an error page that loads.  I get the Hardware Asset form about 50% of the time.
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    Hi Ian,

    This search functionality will ~read CI objects from the ServiceManagement database. Can you take a look and see if you have duplicate hardware asset CIs within the ServiceManagement database, ConfigurationItem table? Something like the following query:
    SELECT * FROM [ServiceManagement].[dbo].[ConfigurationItem]
    WHERE ObjectClassId = 'C0C58E7F-7865-55CC-4600-753305B9BE64'
    AND DisplayName like '%portal%'


  • Ian_GlennIan_Glenn Member IT Monkey ✭
    Hi Joivan,

    That was the issue, I had duplicate CI objects in the "ConfigurationItem" table of the ServiceManagement DB.  I used this KB Article (https://support.cireson.com/KnowledgeBase/View/1142#/) to help me purge the data.  I am only seeing one CI record in my search now and I am no longer getting the error accessing the Hardware Asset form.

    Thanks for your help!
  • Valerie_SirouxValerie_Siroux Customer IT Monkey ✭
    Asset Search functionality is really interesting.

    On the screenshot we also see a view 'My Hardware Assets'
    But we don't have this in our environment. Was this released in a recent version?
    Or is there another way to make this available.
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    Nay, that link is a customization. Since you cannot use the [me] token in a custom grid view within Portal , that link will take the user to their User page, assets tab. This is doable by using the following JavaScript, placing the code segment in your inetpub\CustomSpace\custom.js file. 

    /* ----------------------------------------------- */
    /* ------------- My Hardware Assets  ------------- */
    /* ----------------------------------------------- */
    // v5.0.7.1
    // Description: Adds a link to My Hardware Assets to the navigation node
    $(document).ready(function () {
        if (session.user.AssetManager === 0 && session.user.IsAdmin === false) {
            return;
        }
            
        //The navigation node doesn't load immediately. Get the main div that definitely exists.
        var mainPageNode = document.getElementById('main_wrapper');
        
        // create an observer instance
        var observer = new MutationObserver(function(mutations) {
            //The page changed. See if our element exists yet.
            var hardwareAssetNav = $(".nav_trigger").find("h4:contains(Hardware Assets)").first().parent().find("ul").first();
            if (hardwareAssetNav.length > 0) {
                fn_AddMyHardwareAssets(hardwareAssetNav);
                observer.disconnect();
            }
        });
         
        // configure the observer and start the instance.
        var observerConfig = { attributes: true, childList: true, subtree: true, characterData: true };
        observer.observe(mainPageNode, observerConfig);
        
        //Create the function for adding the my assets link.
        function fn_AddMyHardwareAssets (navNodeListItem) {
            if (navNodeListItem === undefined)  {
                console.log ("Could not find the hardware asset nav node.");
                return;
            }
            
            //The URL should be something like http://scsm-portal/user/UserRelatedInfoById/18b0fd23-cac6-71da-1a03-57b5e9165ca9?tab=assets
            var myAssetsUrl = window.location.origin + "/user/UserRelatedInfoById/" + session.user.Id + "?tab=assets";
            var newHtmlToInsert = "<li>" + "<a target='_blank' href='" + myAssetsUrl + "'>" + "My Hardware Assets</a>" + "</li>"
            
            $(navNodeListItem).append(newHtmlToInsert);
        }
    });
    /* ----------------------------------------------- */
    /* ------------ End My Hardware Assets ----------- */
    /* ----------------------------------------------- */


  • Ian_GlennIan_Glenn Member IT Monkey ✭
    Good Afternoon Joivan, would it be possible to limit the search results to a specific HW Asset Status or HW Asset Type?  Ideally I would only like my users to be able to search for assets in one or more status; as opposed to the entire asset class.  I was reading the API documentation and see there is an option for search criteria, but I cannot find anything that explains how that criteria works.  Thanks!
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    Negative, not with the API out of box. The API call in question is GetConfigItemsByAbstractClass, which only looks at basic config item data. More specifically, it only looks at the generic fields within the ServiceManagement ConfigurationItem database. No real hardware asset data is stored within ServiceManagement yet, so it can't easily be filtered by.
  • Ian_GlennIan_Glenn Member IT Monkey ✭
    Thanks Joivan, do you know if this is something that might be possible down the road?
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    We are currently working on Portal WorkItem parity for ConfigItems, but I'm not sure of the specific roadmap for HardwareAsset API additions. I would lean towards no in the immediate and near future, and "probably" in the intermediate future. 
  • Valerie_SirouxValerie_Siroux Customer IT Monkey ✭
    Thanks Joivan
    Would it also be possible to set the MyAsset directly on the Navigation Node? So, only 1 click is needed to view the assets? 
    I found a way to move it to another node, but I would like it to open instantly.

    To clarify, see the image below. I got it working when clicking the My Hardware Assets link, but I would like to open it when clicking on the My Assets next to the green arrow.

    Is that possible?


  • Eric_KrasnerEric_Krasner Customer Adept IT Monkey ✭✭
    I added the code to my custom.js file, but do not get the new link.  Any thoughts?
  • Eric_KrasnerEric_Krasner Customer Adept IT Monkey ✭✭
    Never mind, I figured it out.  It was located in the Hardware Asset Management node.
  • Eugene_RackEugene_Rack Customer IT Monkey ✭
    I.T Monkey O.G - thanx for the .js code to do a Asset Hardware search. I wonder if you can extend the search criteria please. In the search the field it searches against is dataTextField: "DisplayName". I was wondering if there is some extra code to do dataTextField: "DisplayName" or dataTextField: "AssetTag". We have some assets that are created with Displayname / asset name of Tablet, however we do have asset tags for each and would like to search against that field as well. Thanx, Eugene
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    Thanks Joivan
    Would it also be possible to set the MyAsset directly on the Navigation Node? So, only 1 click is needed to view the assets? 
    I found a way to move it to another node, but I would like it to open instantly.
    Yep, most definitely. In the Portal > Navigation settings, use the "New Link" button to create a static HTML link at the root of the nav node. Call it "My Assets". Don't give it any particular URL. 
    Next, you can use the following code to redirect the newly-created nav node it to the currently logged-on user's asset page. Note: For best results with all browsers, it might work best with a timeout or observer, but this code will work a majority of the time. 

    $(document).ready(function () {
        var myAssetsNavLink = $(".nav_hover").find(".nav_title:contains(My Assets)").first().parent()
        //The URL should be something like http://scsm-portal/user/UserRelatedInfoById/18b0fd23-cac6-71da-1a03-57b5e9165ca9?tab=assets
        var myAssetsUrl = window.location.origin + "/user/UserRelatedInfoById/" + session.user.Id + "?tab=assets";
        myAssetsNavLink.prop("href", myAssetsUrl);
        myAssetsNavLink.prop("target", "_blank");
    });
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    I.T Monkey O.G - thanx for the .js code to do a Asset Hardware search. I wonder if you can extend the search criteria please. In the search the field it searches against is dataTextField: "DisplayName". I was wondering if there is some extra code to do dataTextField: "DisplayName" or dataTextField: "AssetTag". We have some assets that are created with Displayname / asset name of Tablet, however we do have asset tags for each and would like to search against that field as well. Thanx, Eugene
    Currently, searching against hardware asset fields isn't possible OOB - it's something that we are looking at. DisplayName is the only real field currently available. Fortunately, the DisplayName isn't actually set on any form so you can get creative with it in order to enable searching. An easy method to search by asset tag or serial number is to have a runbook/workflow/process modify your asset display names (NOT your asset names) to include the data that you are looking for.

    For example, the display name could be AssetName (SerialNumber) [AssetTag]. This would allow you to use asset searching within the portal for any of the three fields. 
  • R_DelawderR_Delawder Member Adept IT Monkey ✭✭
    I tried the search out and it works but doesn't allow for spaces in the input box. Is there a way to make the input box accept space. When I type the space it scrolls the nav bar instead of entering a space. Software asset searches if I type "Microsoft Outlook" for example it goes in as "MicrosoftOutlook" and doesn't get results.
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    Interesting find. The control seems to lose focus intermittently, even when it has already been selected and you are currently typing in it. For now, a workaround is to add a .focus() to the control. Something like changing the following should work.

    ---Original---
    change: function(e) {
        $("#searchAsset").data("kendoAutoComplete").value("");
    }

    ---New---
    change: function(e) {
        $("#searchAsset").data("kendoAutoComplete").value("");
        $("#searchAsset").focus();
    }
  • R_DelawderR_Delawder Member Adept IT Monkey ✭✭
    Thanks, I tried that and it didn't seem to make any difference, still scrolls nav bar instead of space. (tried in both IE and chrome with same result)
  • Cindy_BoyerCindy_Boyer Customer IT Monkey ✭
    Joivan, I tried this and it worked to search on Display Name. I wish we had chosen to use SerialNumber as the Display Name when we imported, but we used that field for the computer name. I know it's not "set" on the forms, but I'm not sure how we would have a runbook/workflow/process modify the asset display names (yes I know, NOT the asset names) to include the Display Name without breaking the import. Am I making this too hard?
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    Thanks, I tried that and it didn't seem to make any difference, still scrolls nav bar instead of space. (tried in both IE and chrome with same result)
    I think I see - for me, it works consistently if on a page where the nav bar is statically expanded already. But when on a page where the nav bar can pop out and retract, I get intermittent results. Let me investigate this one.

    Joivan, I tried this and it worked to search on Display Name. I wish we had chosen to use SerialNumber as the Display Name when we imported, but we used that field for the computer name. I know it's not "set" on the forms, but I'm not sure how we would have a runbook/workflow/process modify the asset display names (yes I know, NOT the asset names) to include the Display Name without breaking the import. Am I making this too hard?
    Aye, while there is no field within hardware assets to set the display name, whenever you edit a form and apply/OK the changes, the form itself will change the display name to be the same as the Asset Name. So an initial import wouldn't be reliable. 
    For more consistent results for changing your asset Display Names, I would suggest an Orchestrator Runbook with a short-timed schedule along with some PowerShell. Or if you prefer not to use Orchestrator, a Service Manager workflow on a schedule (c# or PowerShell) would also work.
  • Ian_GlennIan_Glenn Member IT Monkey ✭
    Hi Joivan, have you found a fix for the navigation bar retracting when a user tries to select an item from the search results?  We've found that if the user selects a view from the nav bar so that it gets pinned then they can use the search without issue, but if they try to use the search without selecting a view first as soon as they move the mouse to select one of the search results the nav bar closes leaving a floating results window which confuses some staff. Thanks
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    @Ian_Glenn @R_Delawder
    I've made a couple changes that fixes the nav node from hiding, and fixes (well, seamlessly works around) the space bar not working in certain situations. Check out the attached copy and see if it works for you.
  • Steve_ClarkeSteve_Clarke Customer Adept IT Monkey ✭✭
    Just confirming the nav node issue is resolved for us now. Thanks Joivan.
  • Steve_ClarkeSteve_Clarke Customer Adept IT Monkey ✭✭

    Jovian, would it be possible to apply your nav node fix to the following? It was bassed of your original script so suffers the same problem.

     https://community.cireson.com/discussion/425/user-information-ci-search-page-for-analysts

  • Thomas_StrombergThomas_Stromberg Premier Partner Advanced IT Monkey ✭✭✭
    @Ian_Glenn @R_Delawder
    I've made a couple changes that fixes the nav node from hiding, and fixes (well, seamlessly works around) the space bar not working in certain situations. Check out the attached copy and see if it works for you.
    Does this work on the 5.2pr? been doing some testing with the asset search and it does not work as it should for me in this version. 
  • R_DelawderR_Delawder Member Adept IT Monkey ✭✭
    Thanks, for adjusting this, the space bar still scrolls the nav bar instead of providing a space. After putting in the new script I get 3 search boxes in IE and in Chrome it looks fine (only has 1 search box) but still scrolls instead of adding a space. (note I upgraded to pr5.2 since last test same issue there)
  • Ian_GlennIan_Glenn Member IT Monkey ✭
    @Ian_Glenn @R_Delawder
    I've made a couple changes that fixes the nav node from hiding, and fixes (well, seamlessly works around) the space bar not working in certain situations. Check out the attached copy and see if it works for you.
    Hi Joivan, the new script works fine in Chrome (v 52.0.2743.116) but has issues in Internet Explorer.. In IE 11 the search box doesn't always appear immediately, sometimes you have to select a view from that NAV node for it to appear (no errors in the F12 Console).  In IE 10 the search box never appears and all of the views are broken, I get the attached error in the F12 Console.  I tried clearing the cache and restarting the browser, but I get the same result.

    I put the previous version of the script back into my CustomSpace folder and the errors in IE 10 go away and the search appears as it did before.
  • joivan_hedrickjoivan_hedrick Cireson Consultant Advanced IT Monkey ✭✭✭
    @Steve_Clarke This is indeed doable. Stay tuned for an updated user asset search.
    @Thomas_Stromberg @R_Delawder I hadn't actually tested with IE on 5.1+. Try this attached updated version which accounts for 5.1+ changes. 
    @Ian_Glenn IE10- doesn't support the MutationObserver object, so you get that error you provided. The attached updated version also contains a legacy file of hardware asset search, which uses a setTimeout method instead. Give that a shot.  
  • R_DelawderR_Delawder Member Adept IT Monkey ✭✭

    the updated version fixed the display in IE and the space now works in chrome but space still doesn't work in IE. (which unfortunately is the required browser for our users as the chrome browser doesn't support cross domain calls that our custom task that call orchestrator use)

  • Ian_GlennIan_Glenn Member IT Monkey ✭
    Joivan, the "legacy" script works as expected for me across all three browsers (IE10, IE11, and Chrome).  Thank you for your assistance!
«13
Sign In or Register to comment.