If condition for True/False field

marcusjcassidy
Kilo Explorer

Hello All,

I have a pretty simple question to ask as I am new to ServiceNow and Javascript, I am creating a new IT Management system and am trying to create a "resolved on creation" button for incidents that have been resolved first time, I have so far done this as a true/false field in ServiceNow, I have tried adding the below code to make it so that when the "resolve on creation" field is checked for the state to automatically be set to closed, below is my code:

function onCondition() {

//if function for when a user selects "resolved on creation" check box to

//automatically set the state to closed

if (u_resolved_on_creation == true) {

  state = "Closed";

}

}

As I am new to javascript/servicenow any explanation as to what i've done incorrectly as well as what i should've put in would be appreciated.

The error i get is when i try to actually check the "resolve on creation" field:

onChange script error: ReferenceError: u_resolved_on_creation is not defined function (){var o=i(m,arguments);return l.apply(n,o)}

2 REPLIES 2

amlanpal
Kilo Sage

Hi Marcus,



If you are using it in your Client Side scripting then the code will be below:


if (g_form.getValue('u_resolved_on_creation') == 'true') {


  state = "Closed";


}



If you are using it in your Server Side scripting then the code will be below. I assume you are using it in UI Action. If so, you mi=ust opt for this


if (current.u_resolved_on_creation == 'true') {


  state = "Closed";


  current.update()


}



It would be better for us to understand and provide you the solution exactly, if you can elaborate your issue with the screenshot.



I hope this helps. Please mark correct/helpful based on impact


Hi marcusjcassidy ,



Were you able to have a look at my response?


If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.


If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View