ServiceNow angularjs:如何将服务器脚本值传递给客户端脚本
我现在在ServiceNow工作,正在创建一个小部件,它可以打开一个嵌入表单的模式窗口。我想预先填充模态表单中的一些字段,但不确定如何进行 以下是打开模式窗口的按钮的HTML:ServiceNow angularjs:如何将服务器脚本值传递给客户端脚本,angularjs,modal-dialog,servicenow,auto-populate,Angularjs,Modal Dialog,Servicenow,Auto Populate,我现在在ServiceNow工作,正在创建一个小部件,它可以打开一个嵌入表单的模式窗口。我想预先填充模态表单中的一些字段,但不确定如何进行 以下是打开模式窗口的按钮的HTML: <div> <input class="btn btn-support" ng-click="c.onbSupport()" type="button" value="Ask a Question"> </div> 最后,这里是我的服务器脚本: var usr = g
<div>
<input class="btn btn-support" ng-click="c.onbSupport()" type="button" value="Ask a Question">
</div>
最后,这里是我的服务器脚本:
var usr = gs.getUserID();
var gr = new GlideRecord('info');
gr.addQuery('opened_for', usr);
gr.query();
if(gr.next()) {
data.parent = gr.getValue('number');
data.short_description = gr.getValue('short_description');
}
var records=[]; //define array first
var usr = gs.getUserID();
var gr = new GlideRecord('info');
gr.addQuery('opened_for', usr);
gr.query();
if(gr.next()) {
var rec={} //define a record
rec.parent = gr.getValue('number');
rec.short_description = gr.getValue('short_description');
records.push(rec); //populate array with records
}
data.records=records; // you need to assign your array as data
在模态形式中,我有两个字段(parent_case和category),我希望分别用data.parent和data.short_description预填充它们。要将服务器脚本值传递到HTML中,我知道您可以执行{{data.parent}。但是,如何将这些值输入到生成模式表单的客户端脚本中?您需要将这些值传递给客户端脚本和“catch” 我假设您正在尝试传递多个值,所以您需要一个数组来保存值并传递到客户端脚本端 服务器脚本:
var usr = gs.getUserID();
var gr = new GlideRecord('info');
gr.addQuery('opened_for', usr);
gr.query();
if(gr.next()) {
data.parent = gr.getValue('number');
data.short_description = gr.getValue('short_description');
}
var records=[]; //define array first
var usr = gs.getUserID();
var gr = new GlideRecord('info');
gr.addQuery('opened_for', usr);
gr.query();
if(gr.next()) {
var rec={} //define a record
rec.parent = gr.getValue('number');
rec.short_description = gr.getValue('short_description');
records.push(rec); //populate array with records
}
data.records=records; // you need to assign your array as data
客户端脚本:
function($scope,spModal) {
/* widget controller */
var c = this;
var infos=c.data.records;//this is the "catch" part
}
注意:我还没有测试这段代码。@alperzzz提供了正确的方法。 要移交数据,您必须使用“共享”属性与嵌入式小部件共享您的记录。在小部件中,您可以填充共享数据。 您可以在中找到所有属性