Please help with Business Rule script.

Annie10
Tera Contributor

Hello,

I have been trying to update the RITM work notes.  Somehow, the script did not work.  Please help review the code and provide suggestion to fix it.  Thank you

 

Annie10_0-1713163010878.png

 

Annie10_1-1713163053042.png

 

1 ACCEPTED SOLUTION

Nick Parsons
Mega Sage

Hi Annie, what sort of debugging have you done? Have you checked that the script is actually entering the if-statement? To me it looks like that is your issue. When you look at the Approval field that you're accessing on your RITM within your code, you'll see that the value for the sys_choice "Not Yet Requested" is "not requested". So your script should be comparing that instead. 

 

Also, since your business rule is a before type of business rule, your script should not call .update() within it:

 

 

var approvalStatus = current.approval;

if (approvalStatus == "not requested") {
  current.work_notes = "This request item has not been reviewed";
}

 

NickParsons_0-1713164172388.png

 

 

Also, small PSA, but please try and include code/errors as text in your question, not as images. You can format your code so it's easy to read. When it's included as text, it makes it easier for us to copy your code into our answers. You can see this post for more reasons why it's not a good idea to include code as an image. 

 

Hope that helps!

View solution in original post

9 REPLIES 9

Thank you @Nick Parsons 

I have learned something new today.

Deepak Shaerma
Kilo Sage

Hi @Annie10 
can you please tell when you want to update your RITM worknotes?


 

Community Alums
Not applicable

Hi @Annie10 ,

Please try to remove current.update(), because your Business rule is before and in before BR there is no need to update.

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

@Community Alums 

Please let me know if a Business Rule is after, it that means I can use current.upda()?  Thank you

Community Alums
Not applicable

Hi @Annie10 ,

In Business rules it is not allowed to use current.update(), if you use current.update() in after BR than in that case it will running in a loop.

But in Before BR there is no need to write update, it updates automatically

 

In rare case you want to use current.update() in after BR you can refer below script 

current.status = 1;
current.setWorkflow(false);
current.update();
current.setWorkflow(true);

You need to do current.setWorkFlow(false);

I hope my explanation helps you.

 

Please mark my answer correct and helpful if it works for you

 

Thanks and Regards 

Sarthak