Querying Service Catalog Tables

ServiceNow開發中咱們在寫代碼查詢request_item表時,常常會遇到想要根據variable的值來做爲查詢條件。可是官方文檔有強調:ide

You cannot directly query the variables of the Service Catalog Request Item table [screqitem]. Instead, query the Variable Ownership table, [scitemoptionmtom], by adding two queries, one for the variable name and another for the value. The query returns the many-to-many relationship, which you can dot-walk to the requested item.code

Wrong example:ip

var gr = new GlideRecord('sc_req_item');
gr.addQuery('variables.variable_iem',item_value);
......

Right example:ci

var request_item_id;
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('sc_item_option.item_option_new.name','item_name');
gr.addQuery('sc_item_option.value','item_value');
gr.query();

while(gr.next()) {
    request_item_id = gr.request_item.sys_id+''; 
}

總結:
1 Variables.variable_name不能做爲record 查詢條件。
2 在肯定record的狀況下,可使用gr.variables.variable_name。開發

相關文章
相關標籤/搜索