Get field value with column label

Habib2
Tera Expert

Hi,

I want to retrieve field values with column labels in script include, i dont have column names, please suggest if its possible.

1 ACCEPTED SOLUTION

Habib2
Tera Expert

Hi, i have a name-value pair field which has only labels, i need to populate values in value fields, 

however I'm able to achieve this with below script, thank you all for your responses 🙂

Habib2_0-1710661512711.png

 
Habib2_1-1710661867058.png

 

View solution in original post

11 REPLIES 11

@Habib2 

I think you can use below function script to achieve this:

 

getAssignedToValue: function() {
        var tableName = 'incident'; // Assuming you want to retrieve from the incident table
        var labelName = 'Assigned To'; // The label name of the field you're interested in

        var gr = new GlideRecord(tableName);
        if (!gr.isValid()) {
            return "Invalid table name: " + tableName;
        }

        gr.query();
        if (!gr.hasNext()) {
            return "No records found in table: " + tableName;
        }

        var assignedToValue;
        var columns = gr.getColumns();
        for (var i = 0; i < columns.size(); i++) {
            var column = columns.get(i);
            if (column.getLabel() == labelName) {
                assignedToValue = gr.getValue(column.getName());
                break;
            }
        }

        if (!assignedToValue) {
            return "Field with label '" + labelName + "' not found in table: " + tableName;
        }

        return assignedToValue;
    },

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Habib2 


var choices = GlideChoiceList.getChoiceList("incident", "close_code");

for (var i = 0; i < choices.getSize(); i++){
		var choiceValue = choices.getChoice(i).getValue();
		var choiceLabel = choices.getChoice(i).getLabel();
		gs.info("Choice Label -> " + choiceLabel + " Choice Value ->" + choiceValue);
}
Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Abdul_Rahiman
Tera Guru

Hi @Habib2 ,

 

 To get display value of any reference field

 

In client script You can use            >> g_form.getDisplayBox('field_name');     

In Server Side Script  You can use  >> gr.getDisplayValue('field_name')

 

 

 To get  value of any reference field

 

g_form.getValue('field_name')

 

 

Thanks and Reagrds,

Abdul

-O-
Kilo Patron
Kilo Patron

Why do you need to do this?

The requirement seems an odd one.

swathisarang98
Giga Sage
Giga Sage

Hi @Habib2 ,

 

You cannot get the value of field by using Field Label (column Label) in order to get the value of any field you have to use Field Name (column name) , if you don't know the field name you can go to backend of table and get the field name, or just right click on the field and you will get column name and use that to get the value.

 

swathisarang98_0-1710620734666.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang