3

I have a built custom search template for a SharePoint Online site collection to return results in a tabular form. The template works and returns the desired data but some of it is not in the format I want. The code is below:

<body>
    <div id="Item_Default">
<!--#_ 
        if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){
            var id = ctx.ClientControl.get_nextUniqueId();
            var itemId = id + Srch.U.Ids.item;
            var hoverId = id + Srch.U.Ids.hover;
            var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default_HoverPanel.js";
            $setResultItem(itemId, ctx.CurrentItem);
            if(ctx.CurrentItem.IsContainer){
                ctx.CurrentItem.csr_Icon = Srch.U.getFolderIconUrl();
            }
            ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl);
            ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();
_#-->
            <div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="DefaultItem" onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_">
                <table cellpadding="4" width="700px">
                <tr>
                <td width="20%" style="text-align:center">_#=ctx.CurrentItem.UPRNOWSNMBR=#_</td>
                <td width="40%" style="text-align:center">_#=ctx.CurrentItem.FullAddress=#_</td>
                <td width="20%" style="text-align:center">_#=ctx.CurrentItem.PlanningCategory_0=#_</td>
                <td width="20%" style="text-align:center">_#=ctx.CurrentItem.PropertyUse=#_</td>
                </tr>
                </table> 
                <div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>

            </div>
<!--#_ 
        } 
_#-->
    </div>
</body>

The column UPRNOWSNMBR only contains whole numbers but it returns it's data with a decimal point like this: 12345.00000

I've created templates that alter data formats on the fly before (changing date format etc) but can't recall how I did it. How can I trim out the decimal point and everything after it leaving the number intact?

3
  • 1
    Alternatively you could also create new property with Type = Integer if the existing UPRNOWSNMBR type is Decimal.Map the crawled property of existing UPRNOWSNMBR to the new one. This can be done in Search Schema of the Search service application.
    – Unnie
    Jan 4, 2016 at 14:44
  • The type is TEXT. In sharepoint online you can only create TEXT and YES/NO type managed properties
    – JonS
    Jan 6, 2016 at 12:16
  • In that case, you can map the crawled property of UPRNOWSNMBR to any of the pre existing Integer type managed property. You can search with Int in schema
    – Unnie
    Jan 6, 2016 at 12:56

1 Answer 1

2

If you know that you have a number 100% of the time with decimal places other than 0, you could transform it using javascript.

parseInt(_#=ctx.CurrentItem.UPRNOWSNMBR=#_)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.