How to write Script include on cmn_location table to give lookup list Status=Active

Hemanth Naidu
Tera Expert
 
3 REPLIES 3

Shaqeel
Mega Sage

Hi @Hemanth Naidu 

 

You can follow this example. This script include will return an array of location names.

 

javascript

var LocationLookup = Class.create();

LocationLookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

getLocationList: function() {

var locationArray = [];

var locationGR = new GlideRecord('cmn_location');

 

locationGR.query();

 

while(locationGR.next()) {

locationArray.push(locationGR.name.toString());

}

 

return locationArray;

},

 

type: 'LocationLookup'

});

 

 

Here's a summary of the steps:

 

  1. Create a new Script Include in ServiceNow.
  2. Name the Script Include "LocationLookup".
  3. Extend the AbstractAjaxProcessor class to allow the script to be called via AJAX.
  4. Create a new method called "getLocationList".
  5. Inside this method, create a new GlideRecord object for the 'cmn_location' table.
  6. Query the table and loop through the results.
  7. For each record, push the name of the location to the locationArray.
  8. Return the locationArray, which now contains a list of all location names.

 

Please note that this is a very basic example and may need to be adjusted based on your specific requirements.

 

Regrds

Shaqeel


***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

***********************************************************************************************************************





Regards

Shaqeel

Amit Verma
Kilo Patron
Kilo Patron

Hi @Hemanth Naidu 

 

Just to be clear with the requirement , you want to populate only those locations in the lookup list which are active. If yes, can you please let me know where you want to populate this list i.e. either on a Catalog Variable or somewhere else ?

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Approval Matrix conditions
Assignment Rules conditions
Catalog Task Rules conditions

On the above records we given location condition when we click the lookup using list it will go the cmn_location table. So, i want to on location table.

HemanthNaidu_0-1706164019869.png