Database view query from sys ID

Wei_ Ling
Tera Guru

hello everyone,


I would like to know that I use database view in the form page, but the sys_id of database view record is not the sys_id commonly used by the system.

 

If I need to query data through the sys_id of database view record, What should I do, and is there an API to solve this problem?(Querying this sys_id directly with GlideRecord is invalid)

 

Wei_Ling_0-1720418340484.png

 

7 REPLIES 7

Yashsvi
Kilo Sage

Hi @Wei_ Ling,

please check below link:

https://www.servicenow.com/community/ham-forum/get-sys-id-of-records-of-a-particular-table-in-databa...

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

 

I read this article, but do not understand how to set up, can you give me a sample code? thank you so!!

Satishkumar B
Giga Sage
Giga Sage

Hi @Wei_ Ling 

 

 

var gr = new GlideAggregate('your_database_view_table');
gr.addQuery('sys_id', 'your_sys_id_value'); // Replace 'your_sys_id_value' with the actual sys_id
gr.query();
if (gr.next()) {
    // Access fields as needed
    var fieldValue = gr.getValue('field_name');
    gs.info('Field Value: ' + fieldValue);
} else {
    gs.info('No records found.');
}

 

 

 

-----------------------------------------------------------------------------------

Please consider marking my reply as Helpful👍  and/or Accept Solution✔️ , if applicable. Thanks!

thank you, but it not work, the database view does not have the sys_id field.

Wei_Ling_0-1720421696702.png