Set the Default value of Reference variable with the first value of the list

Sarah Austria
Giga Guru

I have a reference field "Assignment Group" from the sys_user_grmember table. I have filter this from reference qual with javascript: 'user=' + current.variables.requested_by;

However, I need to set the default value with the first value available from the list? How to do this? 

Can this be possible from the Default value field? Or do I need to write client script? If via client script? How? thanks.

 

find_real_file.png

1 ACCEPTED SOLUTION

Hi Sarah - You need to write a client script to set the value i.e Client Script + GlideAjax approach. You can query the records from the table and add additional logic to filter the record with setLimit(1) to only return one record in a response.

Reference:

https://community.servicenow.com/community?id=community_blog&sys_id=f8ccee25dbd0dbc01dcaf3231f961978

 

- Pradeep Sharma

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Sarah Austria 

it will show the restricted values but you cannot set the default value directly as the 1st value from list

When you use default value in variable it would directly show only 1 value

How are you determining which group is the 1st?

Is it based on the sorting of name? if yes then you can just use orderBy in the variable attributes

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

yes, it is based on the sorting of name (alphabetically). But how to do that? Can I just put it in the default value field? or I need client script? Not sure how to script it.

Hi,

I assume this is for service catalog variable so you can add this in the attributes section of that variable

ref_ac_order_by=name

to be updated in variable attributes

ref_auto_completer=AJAXTableCompleter,ref_ac_columns=name,ref_ac_columns_search=true,ref_ac_order_by=name

Note: this will just sort but won't set the value directly

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I see, thanks. But what I need is to set the default value with the first value on the list that is sorted alphabetically.

Hi Sarah - You need to write a client script to set the value i.e Client Script + GlideAjax approach. You can query the records from the table and add additional logic to filter the record with setLimit(1) to only return one record in a response.

Reference:

https://community.servicenow.com/community?id=community_blog&sys_id=f8ccee25dbd0dbc01dcaf3231f961978

 

- Pradeep Sharma