Prompter class default value (and documentation)

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Prompter class default value (and documentation)

Viewing 4 reply threads
  • Author
    Posts
  • January 14, 2024 at 2:37 AM #50307

    Chris Ju
    Participant

    Hello,

    does anyone had used default values in the prompt dialog? How could i use a default value for the different “control types”?

    The documentation is not sufficient. There it says:

    “Note: the following parameters are valid .addParameter(label, field_name, control type, values_list, default_value)”

    I tried every possible syntax to get this work. No chance.

    What are “control types”? How do i use them? Is there a checkbox type for the prompt dialog?

    Especially i want to know how i could set default value into a text field of the prompt dialog.

    Please help!

    Thanks

    Chris

    • This topic was modified 11 months, 1 week ago by Chris Ju.
    January 14, 2024 at 4:40 AM #50311

    Chris Ju
    Participant

    In general i want to solve the issue that the date and time “mdappointmentdatetime” in the following script is not passing to the date field of the new record. The value for example is “Freitag, 23. Februar 2024 um 13:00:00”. I think it hasn’t something to do with the format because it is accepted when inserting it manually. Maybe there is an timing issue. Also i have an field script in the form of the new record which needs the field to calculate an end date. The field script in generally works. Here is the script:

    function showErrorMessage(message) {
    let errorPrompter = Prompter.new();
    errorPrompter.cancelButtonTitle = '';
    errorPrompter.continueButtonTitle = 'Abbruch';
    errorPrompter.show(message, (status) => {
    // Error message has been shown to the user
    });
    }

    function confirmExecution(question) {
    return new Promise(function(resolve, reject) {
    let prompter = Prompter.new();
    prompter.cancelButtonTitle = 'Abbrechen';
    prompter.continueButtonTitle = 'Fortfahren';
    prompter.show(question, (status) => {
    if (status == true) {
    resolve('Fortfahren');
    } else {
    reject('Abbrechen');
    }
    });
    });
    }

    function createChildRecord() {
    // Fetch data from the clipboard
    var JSONdata = Utils.copyTextFromClipboard();
    var obj;

    // Try to parse the JSON data
    try {
    obj = JSON.parse(JSONdata);
    } catch (error) {
    console.log('Error parsing JSON from clipboard:', error);
    showErrorMessage("Zwischenablage enthält keine gültigen Daten (JSON string not valid).");
    return;
    }

    // Extract data from JSON
    var mdappointmentdatetime = obj.mdappointmentdatetime;
    var mdappointmentaddress = obj.mdappointmentaddress;
    var mdfilenum = obj.mdfilenum;
    var mdappointmentroom = obj.mdappointmentroom;

    // Format the confirmation message
    var confirmationMessage = 'Eintrag mit diesen Daten erstellen?' +
    '\n\n***** Datum/Uhrzeit: *****\n\n' + mdappointmentdatetime +
    '\n\n***** Adresse: *****\n\n' + mdappointmentaddress +
    '\n\n***** Aktenzeichen: *****\n\n' + mdfilenum +
    '\n\n***** Saal/Raum: *****\n\n' + mdappointmentroom;

    // Call the confirmExecution function with the formatted message
    confirmExecution(confirmationMessage)
    .then(() => {
    // User clicked 'Yes', proceed with creating the child record
    console.log("Creating child record with:", obj);

    // Get the parent form and record
    var parentForm = document.getFormWithId(obj.TfFilesFormId_hidden);
    var parentRecord = parentForm.getRecordWithId(obj.TfFilesRecordId_hidden);

    // Create a new child record in the specified field of the parent record
    var newChildRecord = parentRecord.addNewRecordToField('fld-77f19f359038497fbbe07a20454301f8');

    // Set field values for the new child record
    newChildRecord.setFieldValues({
    'fld-e4b947dd1f8042e6ba52e1a438cd0a01': mdappointmentdatetime,
    'fld-4997e582a89444b8a68f1f2126575042': mdappointmentaddress,
    'fld-de8d6fee8162434aa981686302d1f7f5': mdfilenum + "\n\n" + mdappointmentroom
    });

    // Save changes
    document.saveAllChanges();

    // Open the new child record
    var newRecordUrl = newChildRecord.getUrl();
    Utils.openUrl(newRecordUrl);

    })
    .catch(() => {
    // User clicked 'No', log the cancellation
    console.log('Record creation cancelled');
    });
    }
    // Call the function to create child record
    createChildRecord();

    • This reply was modified 11 months, 1 week ago by Chris Ju.
    • This reply was modified 11 months, 1 week ago by Chris Ju.
    January 14, 2024 at 7:58 AM #50314

    Chris Ju
    Participant

    I solved the issue writing to a date field using for example:

    var mdappointmentdatetime = new Date(obj.mdappointmentdatetime);

    and using a python script to convert the non standard date/time to a javascript friendly format.

    Nevertheless the prompter class documentation does not show us something for control types and default values.

    • This reply was modified 11 months, 1 week ago by Chris Ju.
    • This reply was modified 11 months, 1 week ago by Chris Ju.
    • This reply was modified 11 months, 1 week ago by Chris Ju.
    • This reply was modified 11 months, 1 week ago by Chris Ju.
    February 15, 2024 at 8:48 PM #50494

    Daniel Leu
    Participant

    deleted

    • This reply was modified 10 months, 1 week ago by Daniel Leu.
    February 15, 2024 at 9:20 PM #50496

    Daniel Leu
    Participant

    Default values are working, but the default parameter is the 5th one:

    var value_1;
    var value_2;
    function script() {
    var callbackFunction = function() {
    console.log(value_1);
    console.log(value_2);
    };
    let prompter = Prompter.new();
    prompter.addParameter('Label 1', 'value_1', '','','Default Value')
    .addParameter('Label 2', 'value_2', 'popup', ['Option 1', 'Option 2'], 'Option 1')
    .show('Message prompt', callbackFunction);
    };
    script();
Viewing 4 reply threads

You must be logged in to reply to this topic.