0

I have a display template that is working, however it is not displaying the date in the format that I want.

I need it in the following format MM/DD/YY I had someone trying to help but they bailed on me.

I need to get this resolved as soon as possible.

I have tried a variety of methods and none are working I would really appreciate any help. I have attached the code and an image of the date displayed in the incorrect format.

    <html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> 
<head>
<title>List Table Item-Countermeasures-v2</title>

<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>
<mso:ManagedPropertyMapping msdt:dt="string">ListID','ListItemID','ContentTypeId','Link URL':'Path','Property 1':'Title','Property 2':'','Property 3':'','Property 4:'','Property 5':'','Property 6':'StartDate','Property 7':'','Property 8':'','Property 9':'','Property 10':'','FileExtension','SecondaryFileExtension'</mso:ManagedPropertyMapping>
<mso:MasterPageDescription msdt:dt="string">This is the item row template, use this template in combination with the List Table Control template.</mso:MasterPageDescription>
<mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>
<mso:TargetControlType msdt:dt="string">;#SearchResults;#Content Web Parts;#</mso:TargetControlType>
<mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>
<mso:HtmlDesignStatusAndPreview msdt:dt="string">https://share.philips.com/sites/STS020170908232517/_catalogs/masterpage/Display Templates/Search/Item_List_Item-CM-v2.html, Conversion successful.</mso:HtmlDesignStatusAndPreview>
<mso:HtmlDesignConversionSucceeded msdt:dt="string">True</mso:HtmlDesignConversionSucceeded>
<mso:CrawlerXSLFile msdt:dt="string"></mso:CrawlerXSLFile>
<mso:HtmlDesignPreviewUrl msdt:dt="string"></mso:HtmlDesignPreviewUrl>
</mso:CustomDocumentProperties>
</xml><![endif]-->
</head>

<body>
    <div id="TwoLines">
<!--#_
// Give up your names for the properties in the following array
var propertyNames = {"Property 1":"Segment","Property 2":"Region","Property 3":"Description","Property 4":"Assigned To","Property 5":"Start Date","Property 6":"Due Date","Property 7":"Issue Status","Property 8":"Countermeasure-Smart","Property 9":"Gap $","Property 10":"Amount Gap Closed","Property 11":"","Property 12":"","Property 13":""};

var encodedId = $htmlEncode(ctx.ClientControl.get_nextUniqueId() + "_tableitems_");

var linkURL = $getItemValue(ctx, "Link URL");
linkURL.overrideValueRenderer($urlHtmlEncode);
var iconURL = Srch.ContentBySearch.getIconSourceFromItem(ctx.CurrentItem);

var listID = $getItemValue(ctx, 'ListID');
var listItemID = $getItemValue(ctx, 'ListItemID');
var ContentTypeId = $getItemValue(ctx, 'ContentTypeId');



var startDate = new Date($getItemValue(ctx, "Start Date"));

var rowId = encodedId + "row";
var editCellId = rowId + "_cell";

var currentItemIdx = ctx.CurrentItemIdx + 1;
var alternating = currentItemIdx % 2 === 0 ? "ms-alternating" : "";

if (currentItemIdx === 1) {
_#-->
    <thead>
        <tr>
            <!--#_ 
            // Show the file icon
            _#-->

            <!--#_ 

            // Show the properties that aren't empty
            for(var i = 1; i <= 10; i++) { 
                var property = $getItemValue(ctx, String.format("Property {0}", i));
                if(property.managedPropertyName !== String.format("Property {0}", i)) {
                    var propertyName = typeof propertyNames[property.propertyLookupName] === "undefined" ? property.managedPropertyName : propertyNames[property.propertyLookupName];
            _#-->
            <th class="ms-vh2">
                _#= propertyName =#_ 

                <span id="_#= property.managedPropertyName.replace(/ /g, '-') =#_">
                    <span style="" class="sortarrow ms-sortarrowup-iconouter" ></span>
                    <a id="_#= property.managedPropertyName =#_ASC" href="#" title="Ascending" onclick="$getClientControl(this).sortOrRank('_#= property.managedPropertyName =#_ASC');return false;">
                        <img alt="Ascending" src="/_layouts/15/images/sortaz.gif">
                    </a>
                    <a id="_#= property.managedPropertyName =#_DES" href="#" title="Descending" onclick="$getClientControl(this).sortOrRank('_#= property.managedPropertyName =#_DES');return false;">
                        <img alt="Descending" src="/_layouts/15/images/sortza.gif">
                    </a>
                </span>
            </th>
            <!--#_ 
                }
            } 
            _#-->
        </tr>
    </thead>
    <tbody>
<!--#_
}
_#-->
       <tr id="_#= rowId =#_" class="_#= alternating =#_ ms-itmHoverEnabled ms-itmhover">
            <!--#_
            // Show the properties that aren't empty
            for(var i = 1; i <= 14; i++) { 
                var property = $getItemValue(ctx, String.format("Property {0}", i));
                if (property.managedPropertyName !== String.format("Property {0}", i)) {
            _#-->
                <td class="ms-cellstyle ms-vb2">

            <!--#_
                    if(!property.isEmpty)
                    {
                        var value = i === 1 ? String.format("<a href='{0}' class='ms-listlink'>{1}</a>", linkURL, property) : property; 
                    if (Object.prototype.toString.call(property.value) === '[object Date]') {value = startDate.format("MM/dd/yyyy");
}
            _#-->


                    _#= value =#_
            <!--#_
                        if (i === 1 && !listID.isEmpty && !listItemID.isEmpty && !ContentTypeId.isEmpty) {
                            var viewPropUrl = String.format('/_layouts/15/listform.aspx?ListId={0}&ID={1}&ContentTypeID={2}&Source={3}', listID, listItemID, ContentTypeId, window.location.href.split('#')[0]);
            _#-->
                            <span title="Open Menu" class="NotificationDiv ms-ellipsis-a" rel="_#= viewPropUrl =#_" ref="_#= property =#_" path="_#= linkURL =#_" style="cursor: pointer; margin-top: 3px; float: right;">
                                <img alt="Open Menu" src="/_layouts/15/images/spcommon.png" class="ms-ellipsis-icon">
                            </span>
            <!--#_
                        }
                    }
            _#-->
                </td>
            <!--#_
                }
            } 
            _#-->
        </tr>
<!--#_
if (currentItemIdx === ctx.CurrentGroup.RowCount) {
_#-->
    </tbody>
<!--#_
}
_#-->
    </div>
</body>
</html>

Thank you for your help Dorindaenter image description here

0

Are you just looking for something like this:

var revisiondate = $getItemValue(ctx, "PAIntraActiveRevisionDate");
        var ContentExpired = false; 
        if(!$isEmptyString(revisiondate.inputValue))
        {
            var thisdate = new Date();
            var parseRevDate = new Date(revisiondate);
            revisiondate = parseRevDate.format('dd/MM/yyyy');
            if(parseRevDate < thisdate)
            {
                ContentExpired = true;
            }
        }

//HTML section

       if(ContentExpired == true)
                {
                _#-->
                <td id="revisiondateexpired-_#= ListItemIdentifier =#_" class="cpo_RevisionDateExpired" style="padding:10px;"> _#= revisiondate =#_ </td>
                <!--#_
                }else {

                _#-->
                <td id="revisiondateexpired-_#= ListItemIdentifier =#_" style="padding: 10px" class="cpo_RevisionDate"> _#= revisiondate =#_ </td>
                <!--#_
                }
                _#-->
  • I have tried several versions of this and it never works i still get the full thing I will try again with the refinablestring to see if it works – Dorinda Mar 4 at 23:01
  • I must be doing something wrong I cant seem to get this working – Dorinda Mar 4 at 23:08
  • You are using the revision variable in the HTML section right? In the dev tool (F12) in Chrome you can set a breakpoint in the item display template and inspect the values of the variables – Kasper Bo Larsen Mar 4 at 23:18
  • Does the date need to be the RefinableInt??? i have it as a date and i have one as a string? does it make a difference? – Dorinda Mar 4 at 23:20
  • No, a string will do too as long as it matches the date format. "March 5th 2019" will not do but 04/03/2019 will – Kasper Bo Larsen Mar 4 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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