Expand my Community achievements bar.

SOLVED

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

Avatar

Level 6

I'm so close but maybe my script is way to cumbersome and needs to be written in a different way. We ( @Pulkit_Jain_ 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

Avatar

Correct answer by
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

Avatar

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.

Avatar

Level 6

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

Avatar

Correct answer by
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...

Avatar

Level 6

@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?

Avatar

Level 6

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