0

I have a sharepoint list that has a timestamp in one of the columns. I'm adding the timestap via MS Flow. I need the format to be yyyy-MM-ddThh:mm:ssZ (so i can compare later in a REST call) but whenever the value is added into the list it drops the T and the Z and changes the first bit to mm-dd-yyyy. It doesn't matter how i add it. I've tried adding it with a formula in MS Flow (which has the correct format in the input of the flow, but changes in the output side of the flow). I've also tried making a calculated column which converts the timestamp to the proper format, but i can't call a REST query on a calculated column. Any ideas on how i can get a "single line of text" column to display in the correct format?

1 Answer 1

0

You could modify your NewItem.aspx/EditForm.aspx form/s and put the code in a preSaveAction() function to set a single line of text field to the format you want from your REST call. The preSaveAction() functon is part of the Save event on the SharePoint form Save Event Receiver. If you look at the Save button on the form in DEV tools on your browser, you can see where it is looking for a preSave() action. Put your code in the ContentPlaceHolderMain area of the form. You will set it up like this:

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
    <script type="text/javascript" id="MyCustomJS">
        function preSaveAction() {
            //your REST function call
            var timestamp = $("[title*=timestampColumn]").val();
            var formattedDate = yourRestDateFunction(timestamp).toString();

            $("[title*=formattedDateColumn]").val(formattedDate); 
        }
        function yourRestDateFunction(date) {
            //your time format REST code to return the formatted date
            return date;
        }
    </script>
</asp:Content>

NINJA EDIT: Be sure to add your JS reference of course in your forms if you go this route. Put this in the AdditionalPageHead Content Area:

<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
    <SharePoint:ScriptLink ID="ScriptLink1" Name="~SiteCollection/_layouts/15/customjs/jquery-1.xx.x.js" runat="server />
                                           <!--or ~SiteCollection/yourjslibrarylocation/jquery-1.xx.x.js --> 
<asp:Content> 

Doing it in the preSaveAction() will ensure your code runs before the form is saved and any other SharePoint execution takes place. Make sure to put your preSaveAction() before any $(document).ready(function(){}); , $(function() {}); , or _spBodyOnLoadFunctionName.push() type event or it will not fire. This should work to set that column for you like you want it; then just hide the other timestamp field on the view and in the form. Good Luck!!

1
  • Sounds like just what I need. I'll try it out and post how it goes. Thank you.
    – Cody Pace
    Commented Apr 23, 2018 at 17:22

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.