Prompt for input

Viewing 5 reply threads
  • Author
    Posts
  • March 4, 2023 at 2:39 AM #49080

    Jon Millar
    Participant

    Just wondering , could you add a prompt for input that asks the user to “enter a date” and then return what ever records have that date in a field eg “arrival_date”.

    The prompt would simply be “enter search date” and then the returned records would be what ever records match that date.

    Or is there something like a date picker that the prompt could use?

    Any info/tips gratefully received!

    Cheers Jon

    March 6, 2023 at 1:19 AM #49093

    Brendan
    Keymaster

    The Prompter class does not support a date picker. But you could just ask for the date to be entered in as text then use the Date.parse(dateString) function to parse a string into a date.

    March 6, 2023 at 1:42 PM #49098

    Jon Millar
    Participant

    Thanks Brendan, I’ll have an experiment with that. Cheers.

    March 6, 2023 at 3:49 PM #49100

    Daniel Leu
    Participant

    I have a little prompter helper library that makes it easier to use the Prompter, at least for simple cases. You can find it at: https://api.danielleu.com/public/tf5/v1/files/prompterHelper-v2.js

    Place the code in a form named Scripts and call it prompterHelper. Here is a little example:

    document.getFormNamed('Scripts').runScriptNamed('prompterHelper');
    
    async function myFunction() {
      
      try {
      	await textPrompter('Enter date');
    	console.log("Text entered: " + prompterVar);
      } catch (errorText) {
      	// user clicked 'Cancel'
      	console.log('cancelled');
      	return;
      }
      
      // user clicked 'yes'
      // continue with function
      // main code here
      console.log('continue from yes');
    }
     
    myFunction();

    As you see, the entered text is stored in the variable prompterVar. As Brendan showed, this would need to be parsed in order to get date object.

    March 14, 2023 at 12:11 AM #49135

    Jon Millar
    Participant

    Hi Daniel,

    Sorry I didn’t see this until today, but this is great I really appreciate it. I shall have a play around with this and try to incorporate into my db.

    Thanks again! 😁

    July 5, 2023 at 10:10 AM #49664

    Pinny Berlin
    Participant

    Hi Daniel, Brendon,

    This was actually just what I needed for my own database. Here’s the code I used to get it to work:

    document.getFormNamed(‘Scripts’).runScriptNamed(‘prompterHelper’);

    async function Selected_Items_Change_Follow_Up_Date() {

    //Change Follow Up Date for Selected Items
    
    let selected_id = ‘fld-ef53cc6a7a5f4ed2a51f7de0fa046400’;
    let follow_up_date_id = ‘fld-6fa53ab54482495289f38b069d3c713f’;
    
    try {
    await textPrompter(‘Enter Follow Up Date (YYYY-MM-DD):’);
    console.log(“User entered: ” + prompterVar);
    } catch (errorText) {
    console.log(‘User clicked cancel’);
    return;
    }
    
    //let new_date = new Date(‘2023-07-03T00:00:00’);
    let new_date = new Date(Date.parse(prompterVar + ‘T00:00:00’));
    
    for(let baserecord of search.getRecords()) {
    if (baserecord.getFieldValue(selected_id) === true) {
    baserecord.setFieldValue(follow_up_date_id, new_date);
    baserecord.setFieldValue(selected_id, false);
    }
    
    }
    
    document.saveAllChanges();
    }
    
    Selected_Items_Change_Follow_Up_Date();

     

    • This reply was modified 9 months, 1 week ago by Pinny Berlin.
    • This reply was modified 9 months, 1 week ago by Pinny Berlin.
    • This reply was modified 9 months, 1 week ago by Brendan.
Viewing 5 reply threads

You must be logged in to reply to this topic.