How to get the value of a reference record?
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
06-15-2023 02:35 AM
I created a custom table and created an Add to Service Catalog from the table.
I have a table that has a reference filter and from there I want to create a script include and client script to copy the values of the records, but it is not working, can anyone please check if I am doing something wrong?
// Script include
// Client Callable: True
// Name: GetRequestItem
var GetRequestItem = Class.create();
GetRequestItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
get : function(){
// Client側の値を取得
var reqItemSysid =this.getParameter('sysparm_u_u13_sys_id');
if(reqItemSysid){
//CatalogItemを検索
var gr = new GlideRecord('u_u13');
if(gr.get(reqItemSysid)){
//Variablesが持つElementの一覧を取得
var items = gr.variables.getElements();
var objResponse = {};
for(var i = 0;i < items.length;i++){
//フィールド名や値など変数に格納する。
objResponse[items[i].getName()] = {
'getLabel': ''+items[i].getLabel(),
'getDisplayValue': ''+items[i].getDisplayValue(),
'getValue': ''+items[i].getValue()
};
}
//Client側に値を戻す
return JSON.stringify(objResponse);
}
}
},
type: 'GetRequestItem'
});
//Catalog Client Script
//再申請対象 Reference type
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Server側に値を取得する処理 GetRequestItem (新規作成した処理)
var ga = new GlideAjax('GetRequestItem');
ga.addParam('test1', 'get');
ga.addParam('sysparm_u_u13_sys_id', newValue);
//Server側に処理を移行する、非同期で処理が戻ってくる。
ga.getXML(function(response) {
//Server側からの値を取得する
var jsonResponse = response.responseXML.documentElement.getAttribute('answer');
if (jsonResponse) {
//今回はJSON形式の文字で値を格納したのでObjectに変換する。
var objResponse = JSON.parse(jsonResponse);
for (var name in objResponse) {
//同じ名前のFieldに値を設定する
g_form.setValue(name, objResponse[name].getValue);
}
}
});
}
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
06-15-2023 05:12 AM
A simple way to begin troubleshooting is to add alert lines to the Client Script and gs.info or gs.addInfoMessage lines to the Script Include. By doing this strategically, you can confirm that both scripts are running, what is passed between them, and the logic so you can see where it stops working. In this case you'll find initially that your function is not running as it is not identified correctly in the Client Script. I would also change the name in case 'get' is a reserved word, so it would look more like this:
ga.addParam('sysparm_name', 'getRITM');
then, of course, change the name of the function in the Script Include to match.