How to Debug?

manmathpanda
Giga Guru

Hi all,

I want to know how to debug if i have written some business rule or client script and these scripts are not running, then where i have to see and how to debug this or how to find out where is the error?

 

1 ACCEPTED SOLUTION

Hi manmathpanda,

Client Script:whenever you  will use client script (refer bellow image ) their are few things are very imp,

*table :on which table you are writing client script,e.g incident

*type: when this client script will execute and,(right now i used onCnhange())

* field name: this option available only on onchange() and onceiledit(),now i used state that means when i change this field on form your client script should work.(you can use other field also),

now after save your script open the incident record and change the state field and see the result.

also check client script objects g_form,g_user..etc and the functionality.

find_real_file.png

Business Rule:

here also you need to mention table name,and when to run lets say short description contain yess,and at the time of insert record and update,

find_real_file.png

note:when to run,action and script are optional,if you will not provide BR will return true and will true.only condition also you can give.when you check advanced option then only script will appear on form,

Note :make sure that your both client and BR are active.while execution.

use the bellow script to check whether it is running or not.

find_real_file.png

your gs.info msg will appear on top of form.

and check it with opening record of incident and enjoy!!

check others solutions also to get more idea and then start to debug using system log or other using debugger but for newer this is sufficient to get.also refer docs.

if helpful mark it correct and helpful!!

 

Regards,

Varsha.

 

View solution in original post

4 REPLIES 4

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi,

It's two totally different approaches. Client scripts, it depends on what kind of client scripts (onLoad, onChange). does anything happen? Does the web console give out any errors? If you put in a alert in the code, does that appear? For Business Rules you have other tools like e.g. gs.info to put logs in the code to see if it takes the right path with the correct variables, you can set breakpoints and check with script debugger to see how it goes. And of course also the debug business rule to see that the conditions is a match.

If you haven't taken the training at developer.servicenow.com I will totally recommend it: https://developer.servicenow.com/app.do#!/training/landing?v=kingston

 

And you can of course post your code at the community and let others take a look at it to see if we can find some obvious errors 🙂

 

//Göran

Sri61
ServiceNow Employee
ServiceNow Employee

Hi,

You can use the script debugger. Also, refer to Script debugger

 

find_real_file.png

Thanks, Sri

 

goswami_sudipta
Mega Expert

Hello,

 

Other than above approaches, you could put log statements in BR, SI or any server side scripting like below and check your variable values in System Log > All.

  1. gs.log("My Log statement goes here");
  2. gs.info("My Log statement goes here");
  3. gs.warn("My warning statement goes here"); etc.

 

For client script scripting, to check any variable's value or where your control reaches, put logs like below

  1. alert("My Log statement goes here"); - This will generate an alert in your browser
  2. console.info("My Log statement goes here"); - This will generate log statements in your browser console. To open up browser console, click F12, and click on Console tab to view the logs.

Let me know if that helps.

Thanks, Sudi

Hi manmathpanda,

Client Script:whenever you  will use client script (refer bellow image ) their are few things are very imp,

*table :on which table you are writing client script,e.g incident

*type: when this client script will execute and,(right now i used onCnhange())

* field name: this option available only on onchange() and onceiledit(),now i used state that means when i change this field on form your client script should work.(you can use other field also),

now after save your script open the incident record and change the state field and see the result.

also check client script objects g_form,g_user..etc and the functionality.

find_real_file.png

Business Rule:

here also you need to mention table name,and when to run lets say short description contain yess,and at the time of insert record and update,

find_real_file.png

note:when to run,action and script are optional,if you will not provide BR will return true and will true.only condition also you can give.when you check advanced option then only script will appear on form,

Note :make sure that your both client and BR are active.while execution.

use the bellow script to check whether it is running or not.

find_real_file.png

your gs.info msg will appear on top of form.

and check it with opening record of incident and enjoy!!

check others solutions also to get more idea and then start to debug using system log or other using debugger but for newer this is sufficient to get.also refer docs.

if helpful mark it correct and helpful!!

 

Regards,

Varsha.