Jump to content

Store a timestamp and the current user when a file gets submitted


Recommended Posts

On submission of a file, I would like to store a time stamp and the current (authenticated / logged in) user.

I found a javascript to store the  time stamp and tried to add the user, but when I add the submitterId the  script doesn't run:

<script type="text/javascript">function addTimestamp (fileInputId, timestampInputId, submitterId) {
    
 var fileInput = document.getElementById(fileInputId);
 fileInput.addEventListener('change', function () {
  
   if (fileInput.files.length !== 0 ){
    document.getElementById(timestampInputId).value = '[@cbTimestamp*]';
    document.getElementById(submitterId).value = '[authfield:XC_ID]';
   }
 
 });

};

addTimestamp('EditRecordMS_FSR_At', 'EditRecordMS_FSR_Dt', 'EditRecordMS_FSR_Subm');
addTimestamp('EditRecordMS_TPR_At', 'EditRecordMS_TPR_Dt', 'EditRecordMS_TPR_Subm');
addTimestamp('EditRecordMS_InvAt', 'EditRecordMS_InvDt, 'EditRecordMS_Inv_Subm');

</script>

 

Any help sincerely appreciated. Do I have to split the script into two?

Link to comment
Share on other sites

Hi @vanderLeest,

There's an easy way to store the timestamp using Submission Form. You could use this as a field in your table and set the Data type as Timestamp or you can configure this on your DataPage. You can check these articles for full documentation/tutorial.

https://howto.caspio.com/tech-tips-and-articles/common-customizations/stamp-the-time-url-or-ip-address-to-new-and-updated-records/
https://howto.caspio.com/tables-and-views/data-types/

I hope this helps!

Link to comment
Share on other sites

Thanks Meekee, for the tip

I do know how to store a timestamp on a submission and update/report form, which will be a timestamp for the record, (which an also be done on a table)

The Report Datapage I hope to create allows two different users to store 3 separate files (reports), and I want to store who uploaded each file and when, by autofilling the submitter's user ID and a timestamp .

 

Floris

Link to comment
Share on other sites

This maybe not the most elegant solution, but splitting the script into two functions does the trick:

<script type="text/javascript">
function addTimestamp (fileInputId, timestampInputId) {
    
 var fileInput = document.getElementById(fileInputId);
 fileInput.addEventListener('change', function () {
  
   if (fileInput.files.length !== 0 ){
    document.getElementById(timestampInputId).value = '[@cbTimestamp]';
       }
 });

};

addTimestamp('EditRecordMS_FSR_At', 'EditRecordMS_FSR_Dt');
addTimestamp('EditRecordMS_TPR_At', 'EditRecordMS_TPR_Dt');
addTimestamp('EditRecordMS_Inv_At', 'EditRecordMS_Inv_Dt');

function addSubmitter (fileInputId, SubmitterId) {
    
 var fileInput = document.getElementById(fileInputId);
 fileInput.addEventListener('change', function () {
  
   if (fileInput.files.length !== 0 ){
    document.getElementById(SubmitterId).value = '[@authfield:XC_ID]';
       }
 });

};

addSubmitter('EditRecordMS_FSR_At', 'EditRecordMS_FSR_Subm');
addSubmitter('EditRecordMS_TPR_At', 'EditRecordMS_TPR_Subm');
addSubmitter('EditRecordMS_Inv_At', 'EditRecordMS_Inv_Subm');

</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...