Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

catalog client script not working on service portal

etabalon
Mega Expert

When submitting a request via portal, it seems portal is having a hard time executing the catalog client script.

It throws an error when it reaches this line of code

cat client script.png

See attached. Has anyone here have seen this?

Here is the error.."TypeError: Cannot read property 'name' of undefined"

portal error.png

Also, if we validate a variable input if it's a number(Integer) type, when user types in characters, user isn't get prompted.

FYI. Everything works if submitting via the native UI.

Thanks,

Enrique

1 ACCEPTED SOLUTION

Can you remove variable in gereference and try again


    var user1 = g_form.getReference('requested_for', doUser);



also you need to use callback function for department gliderecord


View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Enrique,



You are using g_form.getReference() without callback which may be causing this issue.


use g_form.getReference() with callback method.


http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#getReference



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards
Ankur

Thanks Ankur. That seems to work...i don't get the error now...but my g_form.setValue after calling the reference is not populating my field.



function onChange(control, oldValue, newValue, isLoading) {


   


    if (isLoading || newValue == '') {


          return;


    }


   


    try{


          if (newValue == 'college'){


                var user1 = g_form.getReference('variables.requested_for', doUser);


//                   g_form.setValue('variables.vendor_name',user.name);


//                   g_form.setValue('variables.vendor_tel_no',user.phone);


//                   g_form.setValue('variables.vendor_tel_addr',getDepName(user.department));


 


//                   if (g_form.getValue('variables.vendor_tel_addr') == 'undefined'){


//                           g_form.clearValue('variables.vendor_tel_addr');


//                   }


               


          }else{


                g_form.clearValue('variables.vendor_name');


                g_form.clearValue('variables.vendor_tel_no');


                g_form.clearValue('variables.vendor_tel_addr');


          }


    }catch(e){


          alert('error: ' + e);


    }


}


function doUser(user1){


                g_form.setValue('variables.vendor_name',user1.name);


                g_form.setValue('variables.vendor_tel_no',user1.phone);


                g_form.setValue('variables.vendor_tel_addr',getDepName(user1.department));


 


                if (g_form.getValue('variables.vendor_tel_addr') == 'undefined'){


                        g_form.clearValue('variables.vendor_tel_addr');


                }


               


}




function getDepName(dep){


    var gr = new GlideRecord('cmn_department');


    gr.addQuery('sys_id',dep);


    gr.query();


   


    if(gr.next()){


          return gr.name;


    }


   


}


Hi Enrique,



Can you check by adding alert statements for the value?



Regards


Ankur


Regards
Ankur

Thanks for your input. I really appreciate it. Alert works on desktop UI but not portal...it's weird.