How to get field type on server side(business rule)?

Pallavi12
Tera Contributor

 

How to get field type on server side(business rule)?

Can anyone please suggest me inside for loop in place of  "field name" what can be use so that i can get value of glideElement.

for(var x in current)

{

var glideElement = recObj.getElement("field name");

 

              var descriptor = glideElement.getED();

 

              var result = descriptor.getInternalType();

}

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

Not sure what you are trying to do. It appears as if you want all field types on a given record. Looking at your script recObj is not defined, so I used current. I also found that the sys_meta field causes the glideElement.getED() method to not work. Taking those into account, here is a script that will give you the field names and types for each field in the current record:

var fArray = [];
for (var x in current) {
    if (x != 'sys_meta') {
        fArray.push(x);
    }
}

for (var f = 0; f < fArray.length; f++) {
gs.print('Field: ' + fArray[f]);
    var glideElement = current.getElement(fArray[f]);
    var descriptor = glideElement.getED();
    var result = descriptor.getInternalType();
gs.print('Type: ' + result);
}

Feel free to modify it for your use.

View solution in original post

5 REPLIES 5

Naveen4
Kilo Guru

Hi, Tried this one working for me.

 

var recObj=new GlideRecord('incident');
recObj.query();

while(recObj.next()){


var glideElement = recObj.getElement("caller_id");

gs.print(glideElement.getDisplayValue());

}

 

for your query replace the field name  with any field value.

 

 

Thanks,Naveen