Upvise Form Scripting Samples


Formulas When a form is submitted
On Change

Download Form Template Samples on GitHub

Overview

The Forms application allows to create custom Form Templates. You can even go further and create custom script to integrate it with other Upvise applications.

Form scripting can be as simple as adding 2 fields or as complex as you want, because you have access to the entire UpviseJS API. You can select, create or modify any record from any application and implement custom business and workflow logic with the power of Javacript.

The Form scripting language is Javascript and can be done at multiple levels:

Compute the surface of a room

        =F1*F2;
        

Display the Address of linked company in a formula field

        =(link!=null) ? link.street : "";
        

Display a custom field value of linked project in a formula field

        = (link != null) ? Forms.getCustomField("Projects.projects", link.id, "F1") : "";
        

Display the email of a selected contact field

        var contact = Query.selectId("Contacts.contacts"", F1);
        = (contact != null) ? contact.email : "";
        

Compute a score for a form based on response values

        var good = 0;
        var total = 0;
        var fields = Forms.getAllFields(form);
        for (var i = 0; i < fields.length; i++) {
            var field = fields[i];
            if (field.type == "checkbox" || field.type == "toggle") {
                total++;
                if (field.value != "0" && field.value != "P" && field.value != "") good++;        
            }
        }
        var score = (total > 0) ? Math.round(good*100/total) : 0;
        score + "%";
        

Change automatically an end date field when the start date changes

             var startdate = parseInt(Forms.getValue("F1"));
            enddate = Date.addMonths(startdate, 1);
            Forms.setValue("F2", enddate);
        

Dynamic Combo box options (1)

        = Query.options("Sales.contracts", "contactid=" + esc(link.id));
        

Dynamic Combo box options (2)

Modify the Form name during form submission

        var name = form.name;
        var company = Query.selectId("Contacts.companies", F1);
        if (company != null) name += "-" + company.name + "-" + F2;
        Query.updateId("Forms.forms", form.id, ""name"", name);
    

Create a Contract record from the form details

        var contract = {};
        contract.name = F1;
        contract.startdate = F2;
        contract.enddate = Date.addMonths(F2, 12);
        contract.period = 365; // days
        contract.amount = F3;
        contract.vat = F4;
        contract.note = "Aircon maintenance Contract: " + F5;
        contract.contactid = link.id;
        contract.number = form.name;
        Query.insert("Sales.contracts", contract);
        return 1;
        

Sending an instant notification when a form is submitted if a Form values has at least one NO Response

        var hasFailed = false;
        var fields = Forms.getAllFields(form);
        for (var i = 0; i < fields.length; i++) {
           var field = fields[i];
           if (field.type == "toggle" && field.value == "0") hasFailed = true;
        }
        if (hasFailed == true) {
            var msg = {};
            msg.title = "FAILED " + Query.names("Forms.templates", form.templateid);
            msg.body = "submitted by: " + User.getName();
            msg.onclick = "Forms.viewForm(" + esc(form.id) + ")";
            var emails = "someone@gmail.com"; // leave empty to notify all managers
            Notif.sendNow(msg, emails);
            App.alert("Form has FAILED");
        }
        return 1;
        

Sending a form PDF report in an email during the validation process.

            var company=Query.selectId("Contacts.companies", F1);
            if (company != null && company.email != "") Forms.emailPdf(form.id, company.email, "Email Subject", "Email Body");
        

Creating a Quote when a form is submitted

        var companyid = F1;
        Forms.newQuote(form.id, F1);
        

Create a Task when a form is submitted

        var values = {};
        values.duedate = F1;
        values.contactid = F2;
        values.name = "This is the task name";
        values.description = "This is the task content";
        values.owner = User.getName();
        values.startdate = Date.now();
        var id = Query.insert("Tasks.tasks", values);
        App.alert("New Task Created!");
        return 1;
        

Send by email a CSV File containing all values in the form

             var emails = "youremail@gmail.com";
             Forms.emailCsv(emails, form.id); 
        

How to change the Form ID based on the values of the form during submit

        var name = form.name; // contains the default auto increment number for the form
        var company = Query.selectId("Contacts.companies", F1); // get the name of the company for the F1 field
        name += " - " + company.name;
        Query.updateId("forms", form.id, "name", name);
        

Change a custom field value of the linked Job during submit

         if (link != null) Forms.setCustomField("Jobs.jobs", link.id, "F1", "Form Submitted!"); 

Extract values from barcode Scan

Note: this code supposes that the raw value encoded in the scanned barcode has the format: LABEL1:xxxxx LABEL2:yyyyy

        Forms.setValue("F2", value); // for debug
        var value1 = Forms.extractValue(value, "LABEL1:");
        var value2 = Forms.extractValue(value, "LABEL2:");
        Forms.setValue("F3", value1);
        Forms.setValue("4", value2);

Compute and display a score using a Score label