Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Change the name in Database view

tanz
Tera Expert

Hi,When creating a Database view, the name field which will automatically appends u_ , I want to keep my own name.

Ex: Is should be not u_xyz in name but xyz in Name of database view

3 REPLIES 3

Yashsvi
Kilo Sage

Hi @tanz,

To create a database view in ServiceNow with a specific name format that doesn't include the u_ prefix automatically added by the system, you typically have two main options:

  1. Manual Creation via Script: You can manually create the database view using a script where you explicitly define the name without relying on ServiceNow's automatic naming conventions.

Here's a basic example of how you can create a database view in ServiceNow using a script:

 

var tableName = 'your_table_name';
var viewName = 'xyz'; // Your desired view name without 'u_'

var gr = new GlideRecord(tableName);
gr.addQuery('your_query_conditions_here');
gr.query();

if (gr.next()) {
    // Create the database view
    var viewDef = "CREATE VIEW " + viewName + " AS SELECT * FROM " + tableName + " WHERE your_conditions_here";
    var db = new GlideDBManager();
    db.executeSQL(viewDef);
}

 

Replace 'your_table_name', 'your_query_conditions_here', and 'your_conditions_here' with your actual table name and appropriate query conditions.

2.Modify Automatically Generated Name: If you prefer to use the automated view creation feature but want to modify the name, you can use a script after the view is created to rename it.

 

var viewName = 'xyz'; // Your desired view name without 'u_'
var viewSysId = 'sys_id_of_your_view_record';

var grView = new GlideRecord('sys_db_object');
if (grView.get(viewSysId)) {
    grView.name = viewName;
    grView.update();
}

 

In this script, replace 'sys_id_of_your_view_record' with the Sys ID of the database view record you want to rename.

 

Remember to adjust the script according to your specific requirements and test thoroughly in a non-production environment before deploying changes to your live instance.

Thank you, please make helpful if you accept the solution. 

SN_Learn
Kilo Patron
Kilo Patron

Hi @tanz ,

 

This is expected behavior, any custom database/table/field, etc creation will have 'u_' in front of name in global scope.

You won't be able to remove it. That is the identifier whether it is custom of OOB.

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Community Alums
Not applicable

Hi @tanz ,

This is out of box thing from serviceNow you can not change the name of database, field or table if it created in global scope it contains u_ in the beginning. If you create in custom scope it contains x_ in that.

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak