How to get empty fields in back ground script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2016 10:10 PM
Hi Team,
I have a table with 3 fields, and I created 5 records in that. I need to get empty value fields in none of the record in the field which was filled with data.
As shown example below when I run back ground script i should get out put as , (Field Name + Table Name (Mail ID + test11)
For that I have written back ground script as below
var inc=new GlideRecord(u_test11);
inc. query();
while(inc. next()){
var sysid= inc.sys_id;
var orc= new GlideRecord('u_test11');
orc. get(sysid);
var fields= orc.getFields();
for(var i=0;i<fields.size();i++){
var glideElement= fields.get(i);
if(glideElement=='' ") {
gs. print('table name: "+orc+"#field name: "+glideElement. getName+"@ field value ="+glideElement);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2016 10:30 PM
Hi Keerthi,
I am not sure if you have tried this simple script and this is what your expectation.
var gr = new GlideRecord("u_test11");
gr.query();
while(gr.next()){
if(gr.field1 == '' || gr.field1 == NULL){
gs.print('fieldname: '+gr.field1+" is empty");
}
if(gr.field2 == '' || gr.field2 == NULL){
gs.print('fieldname: '+gr.field2+" is empty");
}
if(gr.field3 == '' || gr.field3 == NULL){
gs.print('fieldname: '+gr.field3+" is empty");
}
}
Thanks,
Sunil Safare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2016 10:36 PM
Hi Sunil,
That is example table I created but if it is incident table with 150 fields this is difficult could you please guide me in another way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2016 11:42 PM
Hi,
the below script should work.
var inc=new GlideRecord('u_test11');
inc.query();
while(inc.next()){
gs.print('test1');
var sysid= inc.sys_id;
var orc= new GlideRecord('u_test11');
orc.addQuery('sys_id',sysid);
orc.query();
while(orc.next()){
gs.print('test2');
var fields= new GlideRecordUtil().getFields(orc);
for(var i=0;i<fields.length;i++)
{
if(orc.getDisplayValue(fields[i])!=''){
gs.print("Table Name:"+orc.sys_class_name+"Field Name:"+fields[i]+"Field Value:"+orc.getDisplayValue(fields[i]));
}
}
}
}