- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2018 02:23 PM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2018 01:26 AM
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.
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,
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2018 02:50 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2018 08:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2018 09:39 PM
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.
- gs.log("My Log statement goes here");
- gs.info("My Log statement goes here");
- 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
- alert("My Log statement goes here"); - This will generate an alert in your browser
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2018 01:26 AM
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.
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,
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.
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.