Update method not working in Scheduled Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 12:37 AM
I have a scheduled job written as -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 12:50 AM
@surbhi_123 Are you using correct field in below line of code. You said value is not getting set in "u_notice_field" field but you have used "u_notice_domain" field in below line of code.
appSer.u_notice_domain = unique.toString();
I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 12:52 AM
The field name is - u_notice_domain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 01:00 AM
@surbhi_123 , Can you try with this Update Script?
(function(){
var appSer=new GlideRecord('cmdb_ci_app_server');
appSer.addEncodedQuery('sys_idISNOTEMPTY');
appSer.query();
while(appSer.next()){
gs.log("sj run");
var gr = new GlideRecord('cmdb_rel_ci');
var sysId = 'b25bb2c7db38abc076b9ee71ca9619a5';
gr.addEncodedQuery('parent.sys_class_name=cmdb_ci_appl^child.sys_id='+sysId);
gr.query();
var arr = [];
while (gr.next()) {
var appSysID = gr.parent;
gs.log("app sys id" + appSysID);
var gp = new GlideRecord('cmdb_ci_appl');
gp.addQuery('sys_id', appSysID);
gp.query();
while (gp.next()) {
var x = gp.u_notice_domain.toString();
gs.log("x val:"+x);
x = x.split(',');
for (var i = 0; i < x.length; i++) {
arr.push(x[i]);
}
}
}
gs.log("arr length:"+arr.length);
var unique = [];
var seen = {};
for (var i = 0; i < arr.length; i++) { /
var val = arr[i];
if (!seen[val]) {
seen[val] = true;
unique.push(val);
}
}
gs.log("set unique" + unique);
appSer.u_notice_domain = unique.join(',');
appSer.update();
}
})();
Regards,
Shyamkumar
Regards,
Shyamkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 01:13 AM
In the logs of set unique I am getting value as - "set unique bbbc1cce0f1fd200b11cf68ce1050e2e,700d148e0f1fd200b11cf68ce1050e10,603d1cce0f1fd200b11cf68ce1050e1e,511d1cce0f1fd200b11cf68ce1050e1d"
And using unique.join(,) it is not updating