- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 12:16 AM
Hi,
I have fields on the table as mentioned in array. But when i try to display the value in for loop , it is not displayed. It enters the for loop though.
Below is the code in the business rule.
var daysOfWeek = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
for(i=0;i<daysOfWeek.length;++i)
{
gs.addInfoMessage(current.daysOfWeek[i]);
if(current.daysOfWeek[i] > maxHoursPerDay){
gs.addInfoMessage(current.daysOfWeek[i]);
gs.addErrorMessage(gs.getMessage('Maximum hours per day cannot exceed {0} hours', maxHoursPerDay));
current.setAbortAction(true);
}
}
Please let me know what is wrong in the code.
When i try to display current.monday directly , it displays the right value of the field.
Why is it not fetching the field name from array? Please help.
Thanks,
Divya.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 12:48 AM
Hi Divya,
To get it working you need to replace "current.daysOfWeek[i]" with "current[daysOfWeek[i]]" in your script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 12:32 AM
Hi Divya,
What is maxHoursPerDay in your script.
if(current.daysOfWeek[i] > maxHoursPerDay)
And if you want to access daysOfWeek array which you have declaraed above you only need to write daysOfWeek[i];
Thak you,
Ashutosh Munot
Please Hit Helpful, Like or Correct answer if you get proper response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 12:35 AM
See Below Script:
var daysOfWeek = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
gs.print(daysOfWeek );
for(i=0;i<daysOfWeek.length;++i)
{
gs.print(daysOfWeek[i]);
}
Response:
*** Script: monday,tuesday,wednesday,thursday,friday,saturday,sunday
*** Script: monday
*** Script: tuesday
*** Script: wednesday
*** Script: thursday
*** Script: friday
*** Script: saturday
*** Script: sunday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 02:18 AM
Thank you for your reply Ashutosh. But i want to fetch the values of the fields monday, tuesday etc. from the current record.
Vitaly's suggestion works fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2017 12:48 AM
Hi Divya,
To get it working you need to replace "current.daysOfWeek[i]" with "current[daysOfWeek[i]]" in your script.