Autopopulate a value from a table on a catalog form

Cupcake
Mega Guru

I need to auto-populate a value from a table to a catalog item. I've done this before, so I am not sure why this is not working.

So I have a catalog item that has a variable called RFC - which is a reference field referencing the change request table.

That table (the change request table) has a field called project id which references the clarity project info table (The variable name in the clarity project info table is called u_id) vs in the change request table (it is called u_project_id).

I wrote an onChange client script that says the below. What is weird is if I use the change request table to pull in the id #, it gives me the sys id instead of the actual number.   I did make sure that at least one of the variables had a display value of "true". But if I use the clarity_project_info table to pull in the id # - then I get an undefined for the value.

Not sure what is going on here.

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

      if (newValue == ''){

              g_form.setValue("vdb_clarity_num", "");

              return:

      }

     

      var clarity_project_info = g_form.getReference('vdb_rfc',CallBack);

}

function CallBack(clarity_project_info) {

      g_form.setValue("vdb_clarity_num", clarity_project_info.u_id);

}

find_real_file.png

Thanks,

Karen

1 ACCEPTED SOLUTION

Madhu27
Tera Expert

getReference is returning an object of a higher level table that does not have that field defined.   You'll need to use a GlideRecord so that you get back the correct object. Please check the following code and modify if any syntax errors



var clarity_project_info = new GlideRecord('parent table name');  


        if (clarity_project_info.get(g_form.getValue('vdb_rfc'))) {  


      g_form.setValue("vdb_clarity_num", clarity_project_info.u_id);


}  



Thanks


PS: hit correct/helpful...if it helps


View solution in original post

8 REPLIES 8

Madhu27
Tera Expert

getReference is returning an object of a higher level table that does not have that field defined.   You'll need to use a GlideRecord so that you get back the correct object. Please check the following code and modify if any syntax errors



var clarity_project_info = new GlideRecord('parent table name');  


        if (clarity_project_info.get(g_form.getValue('vdb_rfc'))) {  


      g_form.setValue("vdb_clarity_num", clarity_project_info.u_id);


}  



Thanks


PS: hit correct/helpful...if it helps


Thank you I am going to try this but the clarity_project_info is the parent table.


I had to tweek it a little bit, but I got it working.



Thanks for the assistance.



Karen


Madhu27
Tera Expert

Please set values of all reference fields individually. you can keep alert statements where ever you want see the actual values.