Most common used methods in servicenow

1517

In this article we will see some OOB common method used for alert, info, and error messages. I will be explaining these methods with example in details.

First lets take a look into Server-side Methods
current.field_name.setError("Hello World"); 
//Will put "Hello World" below the specified field.
gs.addInfoMessage("Hello World"); 
//Will put "Hello World" on the top of the screen.
gs.print("Hello World");	
//Will write to the text log on the file system but not to the sys_log table in the database.
gs.log("Hello World"); 
//Will write to the database and the log file.

 

1. current.field_name.setError(“Hello World”): 

This method used to display error message just below the field. Lets understand this with an example.

Use Case: Suppose before saving the form you want validate it at server end, during validation same got failed, on that case you would like to display error message just below the field for which validation failed.

Solution: In order to do so you can use setError(“Something Went Wrong !!”) to display your message on form so that user can rectify the issue and resubmit the form.

 

2. gs.addInfoMessage(“Hello World”):

This method used to display Information message on the form. Lets understand this with an example.

Use Case: Suppose you want to display the information message just after saving data in database.

Solution: In order to do so you can use gs.addInfoMessage(“Your data has been saved successfully !!”) to display your acknowledgment message on form.

3. gs.print(“Hello World”): 

This method mainly used during troubleshooting of the code, like in background script we used to used it. it is also used to write to the text log on the file system but not to the sys_log table in the database.

4. gs.log(“Hello World”): This method mainly used during troubleshooting of the code, like in background script. It is also used to write to the database and the log file.

 

Now lets see take a look into Client-side Methods
alert("Hello World"); 
//Will pop up a window with "Hello World" and an 'OK' button.
confirm("Hello World");	
//Will pop up a window with "Hello World?" and a 'Ok' and 'Cancel' buttons.
g_form.showFieldMsg("field_name", "Hello World", "error"); 
//Puts "Hello World" in an error message below the specified field.
g_form.hideFieldMsg("field_name"); 
//Hides an error message that is visible under the specified field.

 

1. alert(“Hello World”): This method mainly used for pop up a message on form. You can use this method at client side.

2. confirm(“Are you sure?”): This method mainly used for pop up a message on form along with OK and Cancel button. You can use this method at client side if you want to get re-confirmation from user before performing any action.

Use Case: Suppose you want to delete a record but before performing the operation you would like to get re-confirmation from the user.

Solution: In order to do so you can use confirm(“Are you sure?”) and use if statement to check whether user has clicked on “OK” or “Cancel” button. If they click on “OK” then it will return true else false.

3. g_form.showFieldMsg(“field_name”, “Hello World”, “error”): This method is similar to current.field_name.setError().g_form.showFieldMsg() method except three parameter.

    • first is field name, where you want to display your message.
    • 2nd is message, which you want to display.
    • 3rd is type of message you want to display, like for information just pass the “info” and for error just type the “error”

 

I have explain many more common used method in detailed in the video. Request you to watch the same if looking for detailed info on other common method used in servicenow.

 

I have tried to explain Most common used methods in servicenow with example, hope you liked it!! If still have doubt then ask your query by commenting on this blog.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here