scripts to check variable is empty or not

TMKAM
Tera Contributor

I have create 2 variable as per below

variable A = multiline text

variable B - attachment

 

the above variable is not set as mandatory field and I would like to create a on submit scripts to check base on the below scenario

 

Scenario 1

Variable A = empty

Variable B = empty meaning no attachment

the script should alert with message when requester press order now button

 

Scenario 2

Variable A = not empty

Variable B = empty meaning no attachment

the script is not alert with message and requester can press order now button

 

Scenario 3

Variable A = empty

Variable B = not empty meaning got attachment inside

the script is not alert with message and requester can press order now button

 

thank you

15 REPLIES 15

@Amit Gujarathi 

thank you for the scripts and i receive an error when i try to save the scripts as attach

 

Screen Shot 2023-06-21 at 13.09.32 PM.png

just put the code in the auto generated code from line 2 to line 10


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



@Amit Gujarathi 

sorry i dont really understand what you mean as i'm noob in scripting

thank you

@TMKAM 

 

have you try below script:

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var text = g_form.getValue("test_text");
    var attachment = g_form.getValue("attachment");
    if (text == '' && attachment == '') {
        alert("please add values to variables");
        return false;
    } else if (text = '' && attachment == '') {
        return true;
    } else if (text == '' && attachment != '') {
        return true;
    } else {
        return true;
    }

}

@Ashwini Jadhao 

thank you for the scripts but it still prompt an error message even i have attach the file Variable Attachment and if i enter the some text in Variable Text no error message appear which is correct

 

here are the scripts below for your reference

function onSubmit() {
//Type appropriate comment here, and begin script below
var text = g_form.getValue("u_describe_option_feature_request");
var attachment = g_form.getValue("u_attach_option_feature_request");
if (text == '' && attachment == '') {
alert("please add values to variables");
return false;
} else if (text != '' && attachment == '') {
return true;
} else if (text == '' && attachment != '') {
return true;
} else {
return true;
}

}