Set Todays Date&Time with JS using custom button

Forums Dynamic Forms for SharePoint Set Todays Date&Time with JS using custom button

This topic contains 3 replies, has 2 voices, and was last updated by  Alexander Bautz 3 months, 2 weeks ago.

  • Author
    Posts
  • #25065

    Maciek Grischke
    Participant

    I know about Set Field Value, but I want to set a date and time when I click on Close this case (custom button).

    I assume this could be done with a custom JS. I’ve tried, but I’m struggling to get it working.

    Any help would be much appreciated.

  • #25092

    Alexander Bautz
    Keymaster
  • #25101

    Maciek Grischke
    Participant

    Excellent!

    So here’s what I did:

    // Insert button if case is Open
    function showCloseButton() {
        jQuery("input[id$='_diidIOSaveItem']").before("<input type='button' id='CloseTicket' class='ms-ButtonHeightWidth' style='margin-right:4px;' value='Close this case' onclick='closeTicket()' />");            
    }
    
    function closeTicket(){
    	setFieldValue("Status","Closed");
    	setFieldValue("DUC",false);
    	var dateVal = new Date();
    	spjs.utility.setDateFieldFromDateObject("DateCompleted",dateVal,0);
    	spjs.dffs.triggerSave();
    }

    Thank you!

  • #25123

    Alexander Bautz
    Keymaster

    I’m glad you figured it out – and thanks for sharing your code snippet.

    Alexander

You must be logged in to reply to this topic.