"Default Value" attribute on <g:ui_reference_multi ??

Phuc Sinh
Tera Contributor

Currently, I want to set a default value for a <g:ui_reference_multi tag in UI Macro. I want to set a default group for a reference field, reference to a group table. I tried many ways, adding attribute "value" "display_value", "displayvalue" , "default" but can not set value for this field.


Does the <g:ui_reference_multi in a UI Macro support an attribute for specifying a default value or are there any other ways to achieve this? Thank you! 

I tried to do the same in this article but can not achieve this
https://www.servicenow.com/community/developer-forum/quot-default-value-quot-attribute-on-lt-g-ui-re...

Here is my code:

<g:ui_reference_multi name="watchlist_group_reference_general_other_request" value="7724f897478d311478efca49116d43f8" table="sys_user_group" display_value="name" id="watchlist_group_reference_general_other_request" query="u_applicationsLIKE4378255adbb98d50d101a82dd3961966"/>




5 REPLIES 5

Community Alums
Not applicable

Hi @Phuc Sinh ,

 

The issue could be due to rendering of the form in your instance.

Could you please try the below code-

<g:ui_reference_multi 
    name="watchlist_group_reference_general_other_request" 
    value="7724f897478d311478efca49116d43f8" 
    table="sys_user_group" 
    displayvalue="Group Name" 
    id="watchlist_group_reference_general_other_request" 
    query="u_applicationsLIKE4378255adbb98d50d101a82dd3961966"/>

 

If this doesn't work then you should try to use a client script-

function onLoad() {
    var multiRefField = g_form.getControl('watchlist_group_reference_general_other_request');
    if (multiRefField) {
        // Default value (sys_id of the group)
        var defaultValue = '7724f897478d311478efca49116d43f8';
        // Display value (name of the group)
        var displayValue = 'Group Name';
        g_form.setValue('watchlist_group_reference_general_other_request', defaultValue, displayValue);
    }
}

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

Thank you for your help @Community Alums ,

Now I know the problem, although value has been set to this field on the UI Macro, but it does not display the name of the group on this field. (here it should display the group name "AL5 GHQ Support Group")

PhucSinh_0-1717948008045.png
After I submitted the form, value of the group has been set correctly

PhucSinh_2-1717948560931.png
The question is, are there any ways to show the name of the group on this field? Thank you!

 

 

Community Alums
Not applicable

Hi @Phuc Sinh ,

 

I think you can do it by setting the display of the name field as true in assignment group table.

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

Hi @Community Alums ,

I tried your solution but it still does not work