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

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!

Hi @Nick Parsons 

I apologize, Nick for not doing a great job of debugging.  I still in the process of learning JavaScript and I did not know what I was doing.  Thank you for sharing your experience. It will definitely help me for this learning journey,  Thank you

@Nick Parsons 

Could you please let me know how did you capture the entire code so that I can learn it instead of capturing the code as an image in the near future.  Thank you

No worries 🙂 - Sure, to format your code you can use the Insert/Edit code sample button

NickParsons_0-1713179860081.png

Then in the popup select the language (in this case JavaScript), and paste your code (usually it's easier to format outside of the editor before you paste it).