- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 05:26 PM
How to get the value of a field on a current record using the 'current' keyword if the field name is a variable? Ex: current.u_description returns the description of the current record, say from a Change Request. but what if 'u_description' is a variable?
var result = current.u_description / This produced the result as "Sample Change Request"
Versus
var fieldName = u_description;
var value = current.fieldName //tried this approach #1 - This produced the result as 'undefined'
var value = current+'.'+fieldName //tried this approach #2 - This produced the result as '[object GlideRecord].u_description'
I will have to use the above piece of code from a business rule on change request, so current refers to the current change record.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 09:30 PM
var value = current.fieldName //tried this approach #1 - This produced the result as 'undefined'
The system is searching for the column with the name fieldName, so it is not preferred to use parameter for the variable. If you want to use parameter its better to use getValue function.
var fieldName = 'u_description';
var value = current.getValue(fieldName); //this will work
Mark if it is helpful or correct

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2016 01:27 PM
Thank you sire, you just solved a problem I had!
{this is an IOU for a beer}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 09:37 PM
Hi Hari,
Below statement should work.It will return a value present in that field.
current[ <variable which contains field name> ]
In your case its
var fieldName=u_description;
gs.log('Description: '+current[fieldName]);
Thanks,
Abhinandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 09:55 PM
Thank you Srikanth and Abhinandan. Both of your solutions perfectly worked. You guys made my day, thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 10:03 PM
Its great to hear that your issue got resolved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 10:05 PM
I have another question on top of it. How can I get the value of a field from a reference table?
for example, I need to get the value of 'technical risk' from 'change activity' table. like this, current.u_change_activity.u_technical_risk.
var techRisk = u_change_activity.u_technical_risk;
current.getValue(techRisk ); // This is not working.
Any suggestions?