How to add option to Prompt script

Viewing 2 reply threads
  • Author
    Posts
  • August 4, 2025 at 8:00 AM #52812

    Victor Warner
    Participant

    I would like help with a Form script concerning a prompt.

    The prompt window displays a date field and then 3 further fields:

    1. Field 1: to the type of service,
    2. Field 2: to choose the number of items, and then
    3. Field 3: how to send it items

    It runs from one form (Notarial Act) and once the fields in the Prompt are populated with data, then the script creates a new record with the data entered in another (Linked to) Form (Disbursements). If all 3 fields are populated, 3 records are created in the Linked to Form.

    The script below does this.

    However, I would like to be able to amend the script so that if Field 3 is set to ‘none’, then only 2 records are created.

    Given the way the prompt script is written/structured, I am not sure how to add this option. Any help would be greatly appreciated.

    `

    var date_id = ‘fld-7b9283660edc4c818320ec930d427747’;
    var type_of_disbursement_id = ‘fld-aad6018d791d477f9c0d323c604712a7’;
    var unit_price_id = ‘fld-5dad44183eb04dc38d6c8565e008be25’;
    var no_id = ‘fld-27cb8e3b36c7472eb4967ccb45b804d9’;

    var output = function printOut(continued) {
    if (continued == true) {

    // take date entered in prompt (put into variable date_of_invoice)
    // and format so it can be written

    var vDate_of_invoice_2 = date_of_invoice.replace(/(\d+)\/(\d+)\/(\d+)/, ‘$2\/$1\/$3’);
    var vDate_of_invoice_3 = new Date(vDate_of_invoice_2);

    // var vDate_of_invoice_formatted = vDate_of_invoice_3.toLocaleDateString(‘en-uk’, {year: ‘numeric’, month: ‘2-digit’, day: ‘2-digit’});
    // var vDate_of_invoice_formatted_ISO = vDate_of_invoice_formatted.replace(/(\d+)\/(\d+)\/(\d+)/, ‘$3-$2-$1′);

    if (service_type==’Standard Service’){

    var Type_of_Disbursement_variable = ‘FCDO – apostille (standard service)’;
    var Type_of_Legalisation_Service_variable = ‘Legalisation agent (standard service)’;

    } else {

    var Type_of_Disbursement_variable = ‘FCDO – apostille (restricted urgent)’;
    var Type_of_Legalisation_Service_variable = ‘Legalisation agent (restricted urgent service)’;

    }

    if (service_type==’Standard Service’){

    var cost_of_apostille = ’40’;

    } else {

    var cost_of_apostille = ‘100’;

    }

    if (service_type==’Standard Service’){

    var legalisation_cost = 18 + (18.00 * number_of_apostilles);

    } else {

    var legalisation_cost = 100;

    }

    let entries = [{
    [date_id]: vDate_of_invoice_3,
    [type_of_disbursement_id]: Type_of_Disbursement_variable,
    [unit_price_id]: cost_of_apostille,
    [no_id]: number_of_apostilles

    },
    {
    [date_id]: vDate_of_invoice_3,
    [type_of_disbursement_id]: Type_of_Legalisation_Service_variable,
    [unit_price_id]: legalisation_cost,
    [no_id]: “1”

    },
    {
    [date_id]: vDate_of_invoice_3,
    [type_of_disbursement_id]: “Courier costs (via legalisation agent)”,
    [unit_price_id]: courier_cost,
    [no_id]: “1”

    }

    ];

    for (let entry of entries) {

    let newRecord = record.addNewRecordToField(‘fld-7e308c2071e248fba8012dee54b53b97’);

    newRecord.setFieldValues(entry);

    }

    document.saveAllChanges();

    } else {
    console.log(“Cancel button pressed.”);
    }
    }

    var date_of_invoice;
    var service_type;
    var service_types = [‘Standard Service’,’Restricted Urgent’];
    var number_of_apostilles;
    var number_of_apostillesx = [‘1′,’2′,’3′,’4′,’5’, ‘7’, ‘8’, ‘9’, ’10’];
    var courier_cost;
    var courier_costx = [’75’,’none’];

    let prompter = Prompter.new();
    prompter.cancelButtonTitle = ‘Cancel’;
    prompter.continueButtonTitle = ‘Go’;
    prompter.addParameter(‘Date of invoice: ‘, ‘date_of_invoice’)
    .addParameter(‘Type of Service: ‘, ‘service_type’, ‘popup’, service_types)
    .addParameter(‘Number of apostilles: ‘, ‘number_of_apostilles’, ‘popup’, number_of_apostillesx)
    .addParameter(‘Cost of the courier: ‘, ‘courier_cost’, ‘popup’, courier_costx)
    .show(‘Add date, number of apostilles, service and whether sent by courier’, output);

    `

    August 4, 2025 at 8:40 AM #52813

    Daniel Leu
    Participant

    So when no courier service is needed, you don’t want to create that service record. Following code should do that. In the entries loop, I check for the ‘none’ value, if the entry value matches, I continue the loop with the next value:

    ...
    for (entry of entries) {
       if (entry[unit_price_id] == 'none') {
          continue;
       }
       let newRecord ...
       ...
    }
    ...
    

    Please note that I didn’t run the code. If there’s an issue, please report back.

    • This reply was modified 3 days, 9 hours ago by Daniel Leu.

    Cheers, Daniel
    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    August 5, 2025 at 10:34 AM #52817

    Victor Warner
    Participant

    Daniel,

    Thank you very much. It works as intended.

Viewing 2 reply threads

You must be logged in to reply to this topic.