addOption() in client script?

Sid_Takali
Kilo Patron
Kilo Patron

Hi all,

I have a Client Script where I am adding Choices through addOption() but when I save the record the backend value is populating instead on Label.  

g_form.addOption('u_available_phone', '10', ans1[0]);

6 REPLIES 6

MrMuhammad
Giga Sage

Hi @Siddharam Takali

Please confirm you are setting the correct value also, the third parameter is the label. So are you sure ans1[0] is returning label of choice instead of value?

g_form.addOption('u_available_phone', '10', ans1[0]);

Can you alert(ans1[0]) and see what it returns.

Regards,

Muhammad

Regards,
Muhammad

@Siddharam Takali - Did you get a chance to try the above alert as I suggested? What was the result that you get?

Also, if you can share the script include that will be helpful. 

Regards,
Muhammad

Aman Kumar S
Kilo Patron

Share the whole script, its difficult to understand without the complete code

Best Regards
Aman Kumar

hi Aman please have a look at this code

Client Script -

 var answ = '';
        var con = g_form.getValue('parent');

        var ga1 = new GlideAjax('sn_customerservice.customerPhones');
        ga1.addParam('sysparm_name', 'ConsumerS');
        ga1.addParam('syparm_cons', con);
        ga1.getXML(HelloWorld);

        function HelloWorld(response) {
            answ = response.responseXML.documentElement.getAttribute("answer");
    
            var ans1 = answ.split(",");
            g_form.addOption('u_available_phone', '10', ans1[0]);
            g_form.addOption('u_available_phone', '20', ans1[1]);
            g_form.addOption('u_available_phone', '30', ans1[2]);

        }