Store value other than the display value

raed1
Giga Contributor

Hey guys,

Is there a way to display and store the value on a reference field other than the display value of the table it is referencing? I am currently dynamically trying to populate the Step field, based on the Job Title selection, however I want the 'Step' reference field to display the u_step field on the table instead of the name id (which is set as the display field).

This what I have on the form:

find_real_file.png

This is my script include that I am calling as reference qualifier on the step dictionary item:

var ChangeStep = Class.create();

ChangeStep.prototype = {

      initialize: function() {

      },

  changeOptions : function() {

            var stepList = ' ';

            var jt = current.u_job_title;

            var sl = new GlideRecord('profiles');

            sl.addQuery('u_udc','position');

            if(jt) {

                      sl.addQuery('uc_code',jt.u_it_code);

            }

            sl.query();

            while(sl.next()) {

                      if (stepList.length > 0) {

                                stepList += (',' + sl.u_step);

                      }

                      else {

                                stepList = sl.u_step;

                      }

            },

  return 'u_stepIN' + stepList;

  },

        type: 'ChangeStep'

};

Thanks,

Raed

13 REPLIES 13

ccajohnson
Kilo Sage

It is unclear as to what you are trying to accomplish. Are you wanting to search on step names that are stored in the u_step field? Where does u_job_title point to? Unclear what or where   jt.u_it_code comes from. If you can let us know how it is failing as well as what you want to succeed with, that should guide us in our solution.


raed1
Giga Contributor

Hello Christopher,



Thank you for your reply. I guess the basic problem I am trying to solve is that I only need one column to be displayed on a reference field.



This is what I currently have for a reference field 'Step' on my form when I try to make a selection:



find_real_file.png



What I want: I want only the step column to be displayed and on selection, I want the step value to be displayed.


Harsh Vardhan
Giga Patron

if i am not wrong you want to get u_step value.


then use this in your script stepList = sl.u_step.getDisplayValue(); or stepList = sl.getDisplayValue('u_step');



Dennis R
Tera Guru

I think I get what you're saying.   As a simple analogy, it's like he wants to have a reference field to the sys_user table, but instead of displaying the name field which is the default display value on that table in the reference field, he wants to display, for example, the phone number.



Raed, I think what you need to look at is the attributes field on the dictionary entry for that field, and set the ref_ac_columns, ref_ac_columns_search and ref_ac_display_value attributes to set the display value column for that field and remove the default display value.



So in the dictionary entry for the Step field, set the following attributes:


ref_ac_columns=u_step;ref_ac_columns_search=u_step;ref_ac_display_value=false



Here's a link to the description of those attributes:


http://wiki.servicenow.com/index.php?title=Auto-Complete_for_Reference_Fields



Hope that helps,


--Dennis R



EDIT: My bad, I have the format of the attributes wrong. It should be more like:


ref_auto_completer=AJAXTableCompleter,ref_ac_columns=sys_created_on,ref_ac_columns_search=true,ref_ac_display_value=false,ref_ac_order_by=sys_created_on