logo

NJP

Apply Filter to ADD Button on Impacted Services/CI RelatedList

Import · Sep 19, 2020 · article

ADD Button is not like a traditional related list Button i.e. Edit, New. As the Add button opens up a Pop-up instead of a slush bucket so the default filters using List Controls don't work. The Good News is, this can be achieved by modifying the OOTB Script Include. [Make sure to Assess and accept/reject upgrades to this script include post upgrade]

Story

Put a Default Filter on Impacted CI's Related List on the Change Request form to show only those CI's which doesn't have STATUS = RETIRED when I click on ADD Button.

Solution

The backend functionality of the ADD button is controlled by a Script Include AssociateCItoTask. We are going to add an encoded query to apply as a filter.

1. Go to the cmdb_ci table and apply a filter on List based on your requirements. Right-click on the filter and select a copy query. This copied query will be used in the script include, in our next step.

image

2. Open the AssociateCItoTask Script include. Inside function _getUrl(), On line # 35, add the below line of the script.

url.set("sysparm_query", 'install_status!=7');

Please note - Line number can be different but make sure you group the above line with the existing url.set(..) method.

image

3. Save the Script Include and then open any change request. Scroll down to Impacted Services/CI related list and click on the ADD button . You will see a default filter there.

image

Hurrah! We are done. image

If this was helpful, please make sure to give it a thumbs up [HELFPFUL]. Also, bookmark this for future reference.

Visit my PROFILE for other good articles, that you might love.

View original source

https://www.servicenow.com/community/developer-articles/apply-filter-to-add-button-on-impacted-services-ci-relatedlist/ta-p/2330057