Selecting UI Action button - place the location in the location field

Kusuma Sai
Mega Guru

Hi Team,

I have created a UI action with 'cmn-location' table. when selecting the any location from the list, it was shows as the details of the location, but i need populate selected location into the 'location' field. i tried this script.

 

function getLocations() {
var loc = new GlideModal('show_list');
loc.setPreference('table', 'cmn_location_list');
loc.setPreference('location', this.loc);
loc.render();
}
getLocations();
@Ankur Bawiskar  can you please help me on this

 

1 ACCEPTED SOLUTION

Kusuma Sai
Mega Guru

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_n" value="show_all_location_${ref}"/>
<span id="${jvar_n}" onclick="showAllLocations('${ref}', '${jvar_n}')" title="Select From All Locations" alt="Select From All Locations" tabindex="0" class="btn btn-default icon-list">
<span class="sr-only">Show All Locations</span>
</span>

<script>
// show related list
function showAllLocations(reference, id) {
try {
var tableField = reference;
var tableFieldSplit = reference.toString().split(".");
var elementID = 'lookup.' + reference.toString();
//document.getElementById(elementID).style.display="none";
var thefield = tableFieldSplit[1]; //Identify the reference field this should be attached to.
var thetable = g_form.getTableName(); //This gets whatever table you are on.

var lookupfield = elementID; //Creates the lookup or reference field ID.
var pinclookup = $(lookupfield);

if (pinclookup){
var thetarget = thetable + '.' + thefield;

var url = '$[AMP]'+'sysparm_query=city=York';
//Here you create some variables to get the values of the fields you want in your custom filter.
var theci = g_form.getValue(thefield); //Get Value of field to pass into query
var taskid = g_form.getUniqueValue(); //Get current sys_id to exclude it in the query
//This line builds up the URL filter. Build this just like a reference qualifier.

var refurl = reflistOpenUrl(thetarget, thetarget, thefield, 'cmn_location', 'null', 'false', '');
var refurlquery = refurl + url;
popupOpenStandard(refurlquery, 'lookup');
}

} catch (e) {
jslog('error showing related list');
jslog(e);
}
}

</script>
</j:jelly>

View solution in original post

3 REPLIES 3

Sid_Takali
Kilo Patron
Kilo Patron

Hi @Kusuma Sai Try below code

function getLocations() {
    var loc = new GlideModal('show_list');
    loc.setPreference('table', 'cmn_location');
    loc.setPreference('sys_id', g_form.getUniqueValue()); 
    loc.setPreference('callback', 'onLocationSelected');
    loc.render();
}

function onLocationSelected(selectedRecord) {
    var locationSysId = selectedRecord.sys_id; // or whatever property you're using
    g_form.setValue('location', locationSysId); 
getLocations();

Hi Sid,

 

when i am click on the UI Action button shows as 'Record not found' popup

 

 

Kusuma Sai
Mega Guru

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_n" value="show_all_location_${ref}"/>
<span id="${jvar_n}" onclick="showAllLocations('${ref}', '${jvar_n}')" title="Select From All Locations" alt="Select From All Locations" tabindex="0" class="btn btn-default icon-list">
<span class="sr-only">Show All Locations</span>
</span>

<script>
// show related list
function showAllLocations(reference, id) {
try {
var tableField = reference;
var tableFieldSplit = reference.toString().split(".");
var elementID = 'lookup.' + reference.toString();
//document.getElementById(elementID).style.display="none";
var thefield = tableFieldSplit[1]; //Identify the reference field this should be attached to.
var thetable = g_form.getTableName(); //This gets whatever table you are on.

var lookupfield = elementID; //Creates the lookup or reference field ID.
var pinclookup = $(lookupfield);

if (pinclookup){
var thetarget = thetable + '.' + thefield;

var url = '$[AMP]'+'sysparm_query=city=York';
//Here you create some variables to get the values of the fields you want in your custom filter.
var theci = g_form.getValue(thefield); //Get Value of field to pass into query
var taskid = g_form.getUniqueValue(); //Get current sys_id to exclude it in the query
//This line builds up the URL filter. Build this just like a reference qualifier.

var refurl = reflistOpenUrl(thetarget, thetarget, thefield, 'cmn_location', 'null', 'false', '');
var refurlquery = refurl + url;
popupOpenStandard(refurlquery, 'lookup');
}

} catch (e) {
jslog('error showing related list');
jslog(e);
}
}

</script>
</j:jelly>