Error box missing by script

  • 61 Views
  • Last Post 09 October 2018
Stephen posted this 04 October 2018

I have a transaction table and willing to go through each line and check if the running balance is correct.

the logic is: If last line balance -current withdrawal +current deposit =current balance, the line is correct.

I write the following code, and it does highlight the line with wrong calculation.

 

<Code Start>

using System;

 

int TotalLines = Context.Field("Balance").Items.Count;

       

 

//first, declare the first row with no rule error, checking will be done in the other script

Context.Field("Deposits").Items[0].HasRuleError =false;

Context.Field("Withdrawals").Items[0].HasRuleError =false;

Context.Field("Balance").Items[0].HasRuleError =false;

 

//declare variable

decimal thisLineBalance = 0;

decimal lastLineBalance = 0;

decimal thisLineWithdrawals = 0;

decimal thisLineDeposit = 0;

 

for (int i = 1; i < TotalLines ; i++)  

{

 

    //get balance, deposit and withdrawals of this and next line

    Decimal.TryParse(Context.Field("Balance").Items[i].Text, out thisLineBalance);

    Decimal.TryParse(Context.Field("Balance").Items[i-1].Text, out lastLineBalance);

    Decimal.TryParse(Context.Field("Withdrawals").Items[i].Text, out thisLineWithdrawals);

    Decimal.TryParse(Context.Field("Deposits").Items[i].Text, out thisLineDeposit);

    

    //Start Checking

    if(lastLineBalance - thisLineWithdrawals + thisLineDeposit == thisLineBalance)

    {

        Context.Field("Balance").Items[i].IsVerified = true;

        Context.Field("Deposits").Items[i].IsVerified = true;

        Context.Field("Withdrawals").Items[i].IsVerified = true;

 

        Context.Field("Balance").Items[i].HasRuleError = false;

        Context.Field("Deposits").Items[i].HasRuleError =false;

        Context.Field("Withdrawals").Items[i].HasRuleError =false;

    }  

    else//pop error if the running balance is not match

    {

        Context.CheckSucceeded=false;

        Context.ErrorMessage="Line Running Balance do not match.";    

        

        

        Context.Field("Balance").Items[i].IsVerified = false;

        Context.Field("Deposits").Items[i].IsVerified = false;

        Context.Field("Withdrawals").Items[i].IsVerified = false;          

        

        Context.Field("Balance").Items[i].HasRuleError=true;

        Context.Field("Deposits").Items[i].HasRuleError =true;

        Context.Field("Withdrawals").Items[i].HasRuleError =true;

 

    }

 

}

 

 

<Code End>

 

My problem are....

First,I have 3 lines having error, none of the error message will disappear until I correct all 3 lines with correct values. I expect while I correct anyone of the line, that line will remove the error message(red box).

Second, After I correct back all values, I intentionally change another 3 lines to wrong values and expect it pop 3 red box respectively.However, the result is only highlight as red box for the first line I adjust the value, but not the other.

 

Is it some logic error in my code?

 

It looks really strange and spend me a lot of time already and sincerely look for help.

Thanks 

Order By: Standard | Newest | Votes
Ekaterina posted this 04 October 2018

Hello Stephen,

Is it possible that you provide us your project (or some kind of mock-up project) with sample images that will be able to demonstrate the issue to us?
I suppose that the placement of script inside the project could be wrong. I would place this type of logic into the Document Definition Rules scripts, but I see that you are using the "CheckSucceeded" property and not "NeedVerification" available in the Rules' scripts.

So to give you better advice, we'll need to examine the entire project. You may upload it to any file-sharing service and send us the link and the password, if needed, in the private message.

Best regards

Stephen posted this 04 October 2018

thanks for helping, will share the entire project to you once avaliable in private message.

 

Thanks in advance.

Stephen posted this 08 October 2018

 Hi Ekaterina,

 

Looks like your inbox is full now.

 

Do you mind share me an email so I can share the project to you by OneDrive?

 

Thanks

Ekaterina posted this 08 October 2018

Hello,

Please upload the project  and samples archived with password-protection on any file storage by your choice (for example, it may be dropbox), and then send us the link and the password by private message on this forum.

Stephen posted this 09 October 2018

Hi Ekaterina,

 

I have inbox you the project , please kindly check.

 

Thanks

 

Close