【问题标题】:Servicenow: substitute for $sp.getRecord() in scoped appServicenow:在作用域应用程序中替换 $sp.getRecord()
【发布时间】:2018-03-04 06:26:33
【问题描述】:

在 ServiceNow 的全局应用程序中,您可以使用 $sp.getRecord(); 访问当前记录。但是,这在作用域环境中不可用。是否有替代方法可以访问作用域应用程序中的当前记录?

这是我试图在下面列出的代码:

var gr = $sp.getRecord();
if (gr == null)
    return;

data.tableLabel = gr.getLabel();
data.table = gr.getTableName();
data.sys_id = gr.getUniqueValue();
data.status = gr.state.getValue();
data.name = gr.name.getDisplayValue();
data.team_lead = gr.team_leader.getDisplayValue();
data.code = gr.project_charge_code.getDisplayValue();

【问题讨论】:

  • "访问当前记录"- 用什么样的脚本?在哪里?

标签: angularjs widget servicenow server-side-scripting


【解决方案1】:

我假设这是服务门户的小部件。我相信您应该能够在作用域应用程序中使用$sp.getRecord()。根据API Reference

请注意:以下 API 适用于范围内的应用程序和 在全局范围内的行为可能会有所不同。

但是,如果您仍然遇到问题,一种方法是将其查询为 GlideRecord,如果您有办法引用它。

var gr = new GlideRecord('x_abcd_my_table');
gr.addQuery('number', 'XMT001245');
gr.query();

while (gr.next()) {
    data.tableLabel = gr.getLabel();
    data.table = gr.getTableName();
    data.sys_id = gr.getUniqueValue();
    data.status = gr.state.getValue();
    data.name = gr.name.getDisplayValue();
    data.team_lead = gr.team_leader.getDisplayValue();
    data.code = gr.project_charge_code.getDisplayValue();
}

【讨论】:

  • 嘿,柯克,谢谢!要跟进这一点,您将如何查询您所在的当前记录。例如,addQuery 行,您将如何动态查询当前打开的记录?不确定这对您是否有意义。谢谢!
  • 这取决于您如何加载记录。你在做什么来达到记录?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 2012-08-08
  • 1970-01-01
  • 1970-01-01
  • 2013-01-07
相关资源
最近更新 更多