UI Page, setting default value on choice list

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 06:03 AM
Hey Everyone,
I am very new to UI Page scripting in ServiceNow. For this UI Page, we need to set the default choice list depending on a condition.
If using the UI action, "Mark as False Positive," choice list value defaults to "False Positive" (22).
If using the UI action "Request Exception," choice list value defaults to "Risk Accepted" (2).
Below is the script.
<div class="row form-section form-group" id="reasonDiv">
<div class="col-sm-3 section-title-top is-required control-label">
<label for="substate">
<span class="required-marker"></span>$[gs.getMessage("Reason")]
</label>
</div>
<div class="col-sm-9">
<j:choose>
<j:when test="${JS:sysparm_is_entry == 'true'}">
<g:evaluate var="jvar_not_important">
var cl = GlideChoiceList.getChoiceList('sn_vul_vulnerability', 'substate');
</g:evaluate>
<style>
.hide_this
{
display:none;
}
</style>
</j:when>
<j:otherwise>
<g:evaluate var="jvar_not_important" expression="var cl = GlideChoiceList.getChoiceList('sn_vul_vulnerable_item', 'substate');" />
</j:otherwise>
</j:choose>
<select id="substate" class="form-control" name="substate" onchange="onReasonChange();"
required="required" aria-required="true" style="width: auto;">
<g:options choiceList="${cl}"/>
</select>
<div id="reason_error_messages" style="display:none;">
<div class="outputmsg_div"></div>
</div>
</div>
</div>
I see that is it pushing the options in for the substate field on the sn_vul_vulnerable_item table.
But how can I default the value?
I tried:
<select id="substate" class="form-control" name="substate" onchange="onReasonChange();"
required="required" aria-required="true" style="width: auto;">
<g:options choiceList="${cl}" $[if(onlyFalsePositive == 'true')]/>
</select>
But as soon as I try to add a condition, it throws an error. I am assuming, I am putting the condition in the wrong spot.
I am new and I need help. Any suggestions?