Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Where is the 'BCHMetaData' Script Include referenced in ServiceNow?

matthew_hughes
Kilo Sage

In ServiceNow, I've had to make an amendment to the OOTB Script Include 'BCHMetaData' so that the 'Create sub-capability'  action is removed.. However, I don't feel comfortable doing this and would rather make a clone of the Script Include.

 

However, I need to know where the OOTB Script Include 'BCHMetaData' is currently be used or referenced so that I can make the amendments in those areas too to use my clone.

7 REPLIES 7

@matthew_hughes,

 

That is fine, but it is possible to be used where you may not expect.

 

Try using this script to find where it is referenced in which table:

var searchText = "BCHMetaData";

var tables = [
    "sys_script_include",
    "sys_script",
    "sys_ui_action",
    "sys_ui_page",
    "sys_processor",
    "sys_ui_policy",
    "sys_client_script",
    "sys_security_acl",
    "sys_security_acl_script",
    "sys_transform_map",
    "sysauto_script",
    "sys_trigger",
    "sys_hub_action_type_definition"
];

for (var i = 0; i < tables.length; i++) {

    var table = tables[i];

    var dict = new GlideRecord("sys_dictionary");
    dict.addQuery("name", table);
    dict.addQuery("internal_type", "CONTAINS", "script");
    dict.query();

    while (dict.next()) {

        var field = dict.element.toString();

        var gr = new GlideRecord(table);

        if (!gr.isValidField(field))
            continue;

        gr.addQuery(field, "CONTAINS", searchText);
        gr.query();

        while (gr.next()) {
            gs.print(
                table + "." + field +
                " -> " + gr.getDisplayValue() +
                " [" + gr.getUniqueValue() + "]"
            );
        }
    }
}

 

I checked in my PDI using other Script include and it worked well.

 

Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.

 

Kind Regards,

Ehab Pilloor

 

Hi @matthew_hughes 

A tip for future coding. Don't clone, and don't edit directly. Extension is the way to go. Look at GlideAjax for the syntax. Many OOTB Script Includes are set up as a read-only record ending in SNC and an editable script include not ending in SNC that extends the SNC script include. You then simply declare the function you wish to override with the same name and your custom functionality

 

The customisation occurs when you replace where the original script include is called with your overridden script include, but  - so long as this doesn't mean changing it in dozens of places, which would probably be a worse outcome - this is far cleaner and easier to document, manage, and troubleshoot (e.g., during an upgrade) plus it preserves the original script.

 

However... in this case I would leave well alone as you're likely to break the Workspace functionality. If the sub-capability is an issue in your organisation, handle it with user education instead.

 

I hope this helps!
Mat

bansibhardwaj
ServiceNow Employee

Hello @matthew_hughes ! This is being used to fetch the metadata for the business capability page. The Scripted REST Resource(sys_ws_operation table) has the record getCapabilityMetadata that uses the methods from this script include. Please check the attached screenshots for more info. 

Important Note: As suggested by other users, we highly recommend not to make any customizations to the OOB shipped code and features, as it might cause potential issues in the existing functionalities. 

Scripted_Rest_Resource.pngUIB_Data_Broker.pngThanks!