Preventing Duplicate Results in Searches

I am using HPE Service Manager 9.50. I want to create field to allow users select a City. The list of cities to choose from, I would like pulled from the location table.

Here is my challenge. We have multiple locations with the same City, how can I get the selection to only show 1 name for each city?

  • What is the field type and query you are using?

    If you have 10 location records all with a city of New York, how will you decide which location record should be the one that shows up? Do you not care which location record is actually chosen?

  • It's not really the entire location record that I want to select it's just the City. I would be tempted to create a separate record with just Cities, but I do not want to have to keep that updated when I already have a list of the Cities I need in the location table.

  • In case you're still working on this, I had some time to investigate further. There may be a simpler way to achieve this, but here is a method that works in my basic testing:

    This example is based on the out of box "Location" field on the out of box im.incident.logging format. Even though the field is designed to store the actual location, we will use it to store the city (just for ease of testing).  Feel feel to adapt it your environment/situation as necessary.

    NOTE: Please make a backup of all records referenced below in case you need to restore them for any reason.

    Here are the steps I used:

    1. Log in to the Client as a SysAdmin

    2. Tailoring > Tailoring Tools > Links

    3. Name:probsummary

    4. Search

    5. Locate the link line that says location $ln.query (should be the 2nd of the 3 link lines)

    6. More > Select Line

    7. Edit the link line as follows:

    a) Remove all existing expressions (this is just for testing purposes, if you need to retain any of the existing ones they can be added back after testing is successful)

    b.) Add the following expression:

    if (not  (null( in $File))) then ($ln.query="location=\"" jscall("FirstCity.findFirstLocation", in $File) "\"")

    c) Locate the the Source Field (Fill To/Post From) line with

    In the Target Field (Fill From/Post To) for this line change it from to city

    d) Save

    8. Tailoring > ScriptLibrary

    9. Name: FirstCity

    10 Package: Base Utilities

    11. Add

    12. Enter the following code in the ScriptLibrary record:

    //var locationQuery;
    function findFirstLocation(query)
    //print( "Searching for location starting with " query "..." );
    var locationFile = new SCFile( "location",SCFILE_READONLY );
    var findLocation = locationFile.doSelect( "city#\"" query "\"" );
    if ( findLocation == RC_SUCCESS )
    //print( "Success. Found location starting with " query "." );
    var findFirstRecord = locationFile.getFirst();
    //print( "The first record is:\n" locationFile );
    //print( "The city in the first record is:\n";
    return locationFile.location;
    } else
    //print( "Could not find location starting with " query ". " RCtoString(
    return null

    13. Save

    14. Incident Management > Create New Incident

    15. Enter some text in the location field for the city. For example, I added a new location record with Cape Town as the city. There is already an existing location record with a city of Cape Town.

    16. Click the Fill button.

    RESULT: The proper city should be chosen from the first location record that has that city populated.