I want to check values of fields in an array in business rule. Please help

divya23
Tera Contributor

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.

1 ACCEPTED SOLUTION

vitaly_sukharev
Kilo Guru

Hi Divya,



To get it working you need to replace "current.daysOfWeek[i]" with "current[daysOfWeek[i]]" in your script.


View solution in original post

5 REPLIES 5

Ashutosh Munot1
Kilo Patron
Kilo Patron

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.


Ashutosh Munot1
Kilo Patron
Kilo Patron

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


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.


vitaly_sukharev
Kilo Guru

Hi Divya,



To get it working you need to replace "current.daysOfWeek[i]" with "current[daysOfWeek[i]]" in your script.