- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 03:54 AM - edited 03-16-2024 03:55 AM
Hi,
I want to retrieve field values with column labels in script include, i dont have column names, please suggest if its possible.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 12:47 AM - edited 03-17-2024 12:51 AM
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 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 09:18 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 10:36 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 10:59 AM - edited 03-16-2024 11:02 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 01:11 PM
Why do you need to do this?
The requirement seems an odd one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 01:26 PM
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.
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang