Add "active=true" default filter/reference to a location field

cicgordy
Tera Guru

Hi all, 

Wondering if anyone can help me. 

I have this pop up field, where when I click the location field, I want only active locations to show and not inactive ones.

cicgordy_1-1694167558763.png

This pop up is showing when I click the "consume" UI action, within the consumable record as shown below

cicgordy_2-1694167697153.png

Therefore there is a UI page (HTML and Client script)  that controls this. I will share the scripts so hopefully you'd be able to help. Thanks

 

HTML:

<g:ui_form>
<input type="hidden" id="cancelled" name="cancelled" value="false"/>
<input type="hidden" id="consumable" name="consumable" value="${sysparm_sys_id}"/>
<input type="hidden" id="total_qty" name="total_qty" value="${sysparm_total_qty}"/>
<input type="hidden" id="from_workspace" name="from_workspace" value="false"/>
<j2:if test="$[!empty(sysparm_domain)]">
<input type="hidden" id="sysparm_domain" name="sysparm_domain" value="${sysparm_domain}"/>
</j2:if>
<j2:if test="$[!empty(sysparm_domain_scope)]">
<input type="hidden" id="sysparm_domain_scope" name="sysparm_domain_scope" value="${sysparm_domain_scope}" />
</j2:if>
 
<table width="100%" style="border-spacing:10px; height:100px;">
<tr>
<td rowspan="6" nowrap="true" width="110px" style="vertical-align:top;">
  <img src="images/plugin_activate.gifx" alt="${gs.getMessage('Activate/Upgrade')}" style="vertical-align:top;" />
</td>
</tr>
<tr>
<td style="width:150px; text-align:right;"><label>${gs.getMessage('From stockroom:')}$[SP]</label></td>
<td><label style="margin:9px;">${sysparm_stockroom}</label></td>
</tr>
<tr >
<td style="text-align:right;"><label>${gs.getMessage('Quantity:')}$[SP]</label></td>
<td><input class="form-control" id="qty" name="qty" value="1" label="" type="text" style="margin:9px; width:inherit;"/></td>
</tr>
    <tr>
        <td style="text-align:right;"><label for="${jvar_asset_query}" onclick="" dir="">${gs.getMessage('Asset:')}$[SP]</label></td>
<td><g:ui_reference name="alm_hardware" table="alm_hardware"/></td> 
    </tr>
    <tr>
        <td style="text-align:right;"><label for="${jvar_user_query}" onclick="" dir="">${gs.getMessage('User:')}$[SP]</label></td>
<td><g:ui_reference name="sys_user" table="sys_user"/></td> 
    </tr>
  <tr>
        <td style="text-align:right;"><label for="${jvar_user_location}" onclick="" dir="">${gs.getMessage('Location:')}$[SP]</label></td>
<td><g:ui_reference name="cmn_location" table="cmn_location"/></td> 
    </tr>
 
    <tr id="dialogbuttons">
        <td colspan="3" align="right" style="padding-right:10px;">
            <g:dialog_buttons_ok_cancel ok="return actionOK();" cancel="cancel();"/>
        </td>
    </tr>
</table>
</g:ui_form>
 
Client Script:

function cancel() {
var c = gel('cancelled');
c.value = "true";

// Only destroy the window when user is on platform view
if (!isActionFromWorkspace())
GlideDialogWindow.get().destroy();
}

function actionOK() {
var total_quantity = gel('total_qty').value;
var quantity = gel('qty').value;
var asset_id = gel('alm_hardware').value;
var user_id = gel('sys_user').value;
var location_id = gel('cmn_location').value;
isActionFromWorkspace();

quantity = quantity.replaceAll(',', '');
var regex = /^\d+$/;
if (!regex.test(quantity) || isNaN(quantity)) {
alert(getMessage("Please enter a non-zero number for quantity"));
return false;
}

total_quantity = parseInt(total_quantity, 10);
quantity = parseInt(quantity, 10);

if (quantity > total_quantity) {
alert(getMessage("Please enter a number less than or equal to the number in stock"));
return false;
} else if (quantity < 1) {
alert(getMessage("Please enter a non-zero number for the quantity"));
return false;
} else {
var form = document.forms['form.' + '${sys_id}'];
addInput(form, "HIDDEN", "asset", asset_id);
addInput(form, "HIDDEN", "user", user_id);
addInput(form, "HIDDEN", "locationSysId", location_id);
return true;
}
}


/**
* Determine if the action performed was from platform or on workspace
*/
function isActionFromWorkspace() {
var fromWorkspace = getParmVal('from_workspace') === "true";

// Set the hidden input field that determined whether or not the
// submission was from platform or workspace
var c = gel('from_workspace');

if (fromWorkspace)
c.value = "true";
else
c.value = "false";

return fromWorkspace;
}

/**
* Helper function to get the parameter values from the URL
*
* @Param {string} name of the url parameter to fetch
*/
function getParmVal(name) {
var url = document.URL.parseQuery();
if (url[name]) {
return decodeURI(url[name]);
}
return;
}

 

 

2 ACCEPTED SOLUTIONS

Brad Bowman
Kilo Patron
Kilo Patron

All you have to do is add a property to the ui_reference tag in the HTML:

<td><g:ui_reference name="cmn_location" table="cmn_location" query="active=true"/></td> 

View solution in original post

'active' is not an OOTB column on the cmn_location table.  If you have added this in your environment, check the column name (u_active?) and update the query property accordingly.  You can also filter a list view of locations to only show 'active' ones then copy the query from the breadcrumb and paste it within quotes on this line.

View solution in original post

5 REPLIES 5

You are welcome!