- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
09-07-2023 05:14 AM
Hi All,
I have a requirement to check whether user is there in Computer table on not.I'm writing If/else condition in workflow.Else part is not working.Could you please help me on this.
Script-
var l=current.variables.requested_for;
var gr=new GlideRecord('cmdb_ci_computer');
gr.addQuery('assigned_to',l);
gr.query();
answer = ifScript();
//
function ifScript() {
if (gr.assigned_to!='') {
return 'yes';
}
return 'no';
}
Regards,
Shreya Sinha
解決済! 解決策の投稿を見る。
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
09-07-2023 08:24 AM
You're missing the gr.next() part of the GlideRecord, and all you really need to do is know if a record is returned by the GR or not, so here's one way to do that. It's also best to put all of your code inside the function:
answer = ifScript();
function ifScript() {
var gr=new GlideRecord('cmdb_ci_computer');
gr.addQuery('assigned_to', current.variables.requested_for);
gr.query();
if (gr.next()) {
return 'yes'; //a record was found
}
return 'no'; //a record was not found
}
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
09-07-2023 08:24 AM
You're missing the gr.next() part of the GlideRecord, and all you really need to do is know if a record is returned by the GR or not, so here's one way to do that. It's also best to put all of your code inside the function:
answer = ifScript();
function ifScript() {
var gr=new GlideRecord('cmdb_ci_computer');
gr.addQuery('assigned_to', current.variables.requested_for);
gr.query();
if (gr.next()) {
return 'yes'; //a record was found
}
return 'no'; //a record was not found
}