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.

Json value change

Mahesh137
Tera Contributor

Can someone help here 

Their is a field "source data" in the discovered tem table which contains "assessed _for_Vulnerabilites" :false  in JSON value need to replace it with assessed _for_Vulnerabilites" :true

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@Mahesh137 You can use following script as a reference point to update an attribute in a JSON field.

 

var glideIRE = new GlideRecord('cmdb_ire_output_target_item'); //add your table na,e here
glideIRE.query();
//glideIRE.addQuery(); add your filters here
if(glideIRE.next())
{
    var jsonVal = JSON.parse(glideIRE.getValue('source_data')); //
    //gs.print(jsonVal.);
    
    if(jsonVal['Assessed for Vulnerabilities']){
        var assess=jsonVal['Assessed for Vulnerabilities'];
        if(assess=='false'){            
            jsonVal['Assessed for Vulnerabilities']='true';
            glideIRE.setValue('source_data',JSON.stringify(jsonVal));
            glideIRE.update();
        }
    }

}

Hope this helps.