Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Update method not working in Scheduled Job

surbhi_123
Tera Expert

I have a scheduled job written as -

(function(){
    var appSer=new GlideRecord('cmdb_ci_app_server');
    appSer.addEncodedQuery('sys_idISNOTEMPTY');
    appSer.query();
    while(appSer.next()){
    gs.log("sj run");
    //var sysId =appSer.sys_id;
    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 (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.toString();
 
    appSer.update();
    }
   
})();
 
Here in logs value I am getting the unique value but it is not being set to the u_notice_field name.
 
10 REPLIES 10

I am still not able to update the values here