How to get value from choice option from form

TejasviR
Tera Contributor

Hello Everyone,

I need your help, I need to access the value of the drop-down menu which is available of form, and if the user select ABC from drop-down menu than it will compare the location and if user select XYZ then it will not.

my code:

var ch = g_form.getValue('type_of');

if (ch == "ABC"){

if (g_form.getValue('loc1') == g_form.getValue('loc2')){

g_form.addErrorMessage('Location can't be same');

}retrun false;

}

1 ACCEPTED SOLUTION

Hi,

Please use below script and see what value you get using g_form.getValue().

var ch = g_form.getValue('type_of');
alert('You have selected : '+ch);  / this will help you to get background value of Type variable.
    if (ch == "abc") {  //update this condition with value of choice ()
        if (g_form.getValue('loc1') == g_form.getValue('loc2')) {
            g_form.addErrorMessage('Location can\'t be same ');
            return false;
        }
    }

 

You might be using Label in If condition instead use value of choice 'ABC' for field type_of.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

9 REPLIES 9

The logic shared by Palanikumar is correct.

What is the issue?

Do you want this Error message when user change options and locations are same?

or do you want to stop submissions?

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

I want an error message when locations are the same. only for the ABC scenario.

Hi,

Please use below script and see what value you get using g_form.getValue().

var ch = g_form.getValue('type_of');
alert('You have selected : '+ch);  / this will help you to get background value of Type variable.
    if (ch == "abc") {  //update this condition with value of choice ()
        if (g_form.getValue('loc1') == g_form.getValue('loc2')) {
            g_form.addErrorMessage('Location can\'t be same ');
            return false;
        }
    }

 

You might be using Label in If condition instead use value of choice 'ABC' for field type_of.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Did you try the updated code I shared? Your old code had some syntax errors. I fixed them. Please try and let me know if this there is any other issue

Thank you,
Palani

I have one more question, in my approval mail notification, I put all the fields from my form. so on my form, I have a drop-down menu, if the user select location then the old and new location field will appear. and if the user selects transfer then apart from the locations field user name will also appear. I don't want to create another approval notification so how i can achieve this.

 

Requested ITEM Number: ${document_id.URI_REF}
Item: ${document_id.cat_item}
Type of Movement: ${document_id.variables.type_of_movement}
Requested For: ${document_id.variables.requestedFor_user_name}
Email Id:
${document_id.variables.employee_id}
User Location:
${document_id.variables.user_location}
New User Name:
${document_id.variables.new_user}
New Location:
${document_id.variables.new_user_location}
Asset Details:
${document_id.variables.assets_to_transfer}
Justification: ${document_id.variables.justification}