Reference Lookup Initial Filter

qz8437
Mega Contributor

I thought this would be really simple, but I can't seem to find out how to do it.   First of all, I don't want there to be a reference qualifier (so that there are no restrictions to what records can be placed in the reference field.   Then when the user clicks the reference lookup decoration (spyglass icon), they get a filtered list in the pop-up.   But they can change the filter, or remove it and set a completely different filter that can include records excluded by the initial filter.

Here is a screen-shot showing what I want to happen when they click the spyglass (notice the breadcrumbs are there and are blue [so they are changeable, for example if the record they want isn't in the list, they could get rid of the Active=true]):

Screenshot.jpg

Any ideas of how to set an initial filter for the reference lookup that is then user changeable?

Thanks for the help.

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Reed, the following post will help you out to accomplish this:



https://community.servicenow.com/people/MB/blog/2011/03/09/2475



Thanks,


Berny


View solution in original post

7 REPLIES 7

bernyalvarado
Mega Sage

Hi Reed, the following post will help you out to accomplish this:



https://community.servicenow.com/people/MB/blog/2011/03/09/2475



Thanks,


Berny


I just realized after talking with the user that requested this functionality, that he wants the initial filter to be more dynamic than the onLoad client script in the MB Blog post will allow.   It needs to react to changes to a few different fields.




To accomplish this I changed the onLoad script to an onChange script and duplicated it (one for each field that is part of the filter).   It works perfectly EXCEPT every time it runs it adds another icon.   Does anybody know how I can tweak the pop-up commands to make it update the pop-up instead of creating a new one?   Or failing that, how can I delete the old icon in my client script so the new one can replace it?




Thanks,


Reed


I just found this post useful, so I figured I'd leave it a little cleaner (Boy Scout Rule).



I'd recommend implementing this as a UI Macro instead.


http://wiki.servicenow.com/index.php?title=UI_Macros#gsc.tab=0



Then, use the ref_contributions attribute to call it on the field.


Dictionary Attributes - ServiceNow Wiki



I did this for the Assignment Group to show a list of 'Suggested' Groups.



<?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="suggested_groups_${ref}"/>


<g:reference_decoration id="${jvar_n}" field="${ref}"


  onclick="showSuggestedGroups(); "


  title="${gs.getMessage('Suggested Groups')}" image="images/icons/tasks.gifx"/>



<script>


  function showSuggestedGroups() {


  var thefield = 'assignment_group'; //Identify the reference field this should be attached to.


  var thetable = 'incident'; //This gets whatever table you are on.


  var lookupfield = 'lookup.'+ thetable + '.' + thefield; //Creates the lookup or reference field ID.


  var thetarget = thetable + '.' + thefield;




  var url = "&amp;amp;sysparm_query=active=true";


  var refurl = reflistOpenUrl(thetarget, thetarget, thefield, 'sys_user_group', 'null', 'false', '');


  var refurlquery = refurl + url;


  popupOpenStandard(refurlquery, 'lookup');


  }


</script>


</j:jelly>



It essentially does the same thing.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Hi Paul,

How can I select a record by using this to populate other field?

As I understand it will open a filtered list and its great but can we select it for review info?