Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

If, else and else if statements, need a little help.

nowackem
Level 4
Level 4

I'm so close but maybe my script is way to cumbersome and needs to be written in a different way. We ( @PulkitJain and @Mayank_Tiwari ) had this form working but the customer wanted another functionality added to my tbleEmployeeInfo table. We added a column with a field named adjustedRate. If this field has a value typed in by the user, I need it to overwrite the script that uses the hourlyRateCap field and apply that same logic to the new adjustedRate instead. If the user takes out/deletes the value I need the hourlyRateCap script to run again. Basically we need to make an adjustedRate be the determining factor as to how the script runs. I have placed the original form in my shared folder so you can see how it worked without the extra column, then I have placed the current form in the folder so you can see what I've tried to do. I'm sure you have questions, this is hard to explain.

https://drive.google.com/drive/folders/1gNJSIUYdh-i-sR07mlwzOsl1Fv2jp-s4?usp=sharing

Thank you!

Emilee

1 Accepted Solution
Mayank_Tiwari
Correct answer by
Employee
Employee

Please find the fixed form. I have used the following script to make it work. You need to iterate through the Table rows to make it work. 

 

 form1.Page1.subPayRollInfo.tbleEmployeeInfo.repeatingRow.adjustedRate::exit - (JavaScript, client)
var rows = this.resolveNodes("tbleEmployeeInfo.repeatingRow[*]");

for(var i =0; i<rows.length;i++)
{
if (rows.item(i).hourlyRate.rawValue > rows.item(i).adjustedRate.rawValue) {
  rows.item(i).hourlyRateUsed.rawValue = rows.item(i).adjustedRate.rawValue;
  }
  else if (rows.item(i).hourlyRate.rawValue < rows.item(i).adjustedRate.rawValue) {
 rows.item(i).hourlyRateUsed.rawValue = rows.item(i).hourlyRate.rawValue;
  }
  else if (rows.item(i).hourlyRate.rawValue== rows.item(i).adjustedRate.rawValue) {
 rows.item(i).hourlyRateUsed.rawValue = rows.item(i).hourlyRate.rawValue;
  }  
  
  }

Output:

Mayank_Tiwari_0-1635890596462.png

 

 

Fixed Form: https://drive.google.com/file/d/1NpRKVNiRYnqR9YUhG0zG14tH_2pGXgMj/view?usp=sharinghttps://drive.goog...

View solution in original post

8 Replies
radzmar
Level 10
Level 10

Uhm, not sure I understood what you're trying to archive, but the script in adjustedRate exit event can be much easier: 

 

var a = this.rawValue,
b = hourlyRate.rawValue;
this.rawValue = a <= b ? b : a;
hourlyRate.rawValue = b < a ? a : b;

In general, you're using the resolveNode() method way too much, that's why the form is so slow. 

You don't need it if the references objects are all named and are relative cloade to the object which executes the script. In a table row for examle you can simply address the neighbor cells with their names. And for this.resolveNode("$").rawValue just use this.rawValue.

nowackem
Level 4
Level 4

I was wondering about over using resolveNode(). Thank you!

Mayank_Tiwari
Correct answer by
Employee
Employee

Please find the fixed form. I have used the following script to make it work. You need to iterate through the Table rows to make it work. 

 

 form1.Page1.subPayRollInfo.tbleEmployeeInfo.repeatingRow.adjustedRate::exit - (JavaScript, client)
var rows = this.resolveNodes("tbleEmployeeInfo.repeatingRow[*]");

for(var i =0; i<rows.length;i++)
{
if (rows.item(i).hourlyRate.rawValue > rows.item(i).adjustedRate.rawValue) {
  rows.item(i).hourlyRateUsed.rawValue = rows.item(i).adjustedRate.rawValue;
  }
  else if (rows.item(i).hourlyRate.rawValue < rows.item(i).adjustedRate.rawValue) {
 rows.item(i).hourlyRateUsed.rawValue = rows.item(i).hourlyRate.rawValue;
  }
  else if (rows.item(i).hourlyRate.rawValue== rows.item(i).adjustedRate.rawValue) {
 rows.item(i).hourlyRateUsed.rawValue = rows.item(i).hourlyRate.rawValue;
  }  
  
  }

Output:

Mayank_Tiwari_0-1635890596462.png

 

 

Fixed Form: https://drive.google.com/file/d/1NpRKVNiRYnqR9YUhG0zG14tH_2pGXgMj/view?usp=sharinghttps://drive.goog...

View solution in original post

nowackem
Level 4
Level 4

@Mayank_Tiwari  Great! thank you, this is very close! One issue I'm finding is that when you tab through the fields adding values, and if you leave adjustedRate value null or empty (or type a value then delete it after), hourlyRateUsed becomes a null or empty value. If adjustedRate is empty then I need the script pertaining to the hourlyCapRate to run and put the proper value in hourlyRateUsed. Do you see a way to make that work?

nowackem
Level 4
Level 4

I tried to request access but I dont know if you received the message. Below is what I get when I click on the link.

nowackem_0-1636393426103.png