"Default Value" attribute on <g:ui_reference_multi ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 04:16 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 05:22 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 08:58 AM
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")
After I submitted the form, value of the group has been set correctly
The question is, are there any ways to show the name of the group on this field? Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 02:03 PM - edited 06-09-2024 02:04 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 08:11 PM
Hi @Community Alums ,
I tried your solution but it still does not work