client script , business rule , and server side

sagarpundir
Tera Contributor

Can anybody provide me some deep knowledge of client script , business rule , and server side that all interviewers may ask in their interviews. Some tricky scenarios or some deep knowledge .

1 ACCEPTED SOLUTION

AbinC
Tera Contributor

Hi @sagarpundir ,

 

1. Which type of BR shouldn't include current.update() and why?

  • A "Before" and "After" Business Rule should not include current.update() because it runs before the record is saved to the database. When you update current in a "Before" and "After" rule, it can trigger the same rule again, leading to an infinite loop. This loop can cause performance issues and potentially crash the system.
  • In case if you want to use current.update in before br then use current.setWorkflow(false).

2. Explain advantages of Asynch BR over After BR or vice versa.

  • Advantages of "Asynchronous" Business Rules:

    • They run in the background, minimizing the impact on user experience.
    • Suitable for time-consuming processes like data calculations, sending notifications, or integrations.
    • Ideal for long-running tasks that don't require immediate user feedback.
  • Advantages of "After" Business Rules:

    • They execute immediately after a record is saved, allowing for real-time actions.
    • Useful for scenarios where you need to interact with the user interface, such as showing confirmation messages.
    • Better for tasks that require immediate updates visible to the user.

3. Can we call a scheduled job from BR?

  • No, you cannot directly call a scheduled job from a Business Rule. Scheduled jobs are independent processes managed by the ServiceNow scheduler. However, you can indirectly trigger a scheduled job by creating a condition in the Business Rule that inserts a record or changes a field that the scheduled job monitors. This way, the scheduled job will execute based on its configured schedule and conditions.

4. Did you ever call a script include in BR? Why do we call a script include in BR if we can write the same script in BR itself?

  • Yes, it's common to call script includes in Business Rules. The main reasons are code reusability, maintainability, and modularity. Script includes allow you to centralize and reuse code across multiple Business Rules, scripts, and modules. This approach promotes consistency and reduces the risk of duplicating code. Additionally, script includes can be easily tested and updated independently, enhancing code management and troubleshooting capabilities. Writing the same script directly in a Business Rule may lead to code redundancy, making it harder to maintain and troubleshoot.
  • Calling script include in br: var gr=new scriptinclidename().scriptincludefunctionname(any parameters you want to pass)

 

1. How do you debug BR? What are the different ways to debug BR?

  • Debugging Business Rules can involve techniques like:
    • Adding gs.log() statements to log messages to the system log.
    • Setting breakpoints in the Business Rule.
    • Using the "Script Debugger" tool to step through the script.
    • Examining the system logs to trace the execution flow.

2. Explain any scenario where we can't use Asynch BR?

  • You might avoid using an "Asynchronous" Business Rule when:
    • Real-time user interaction is necessary immediately after record save.
    • You need to show user feedback, such as pop-up messages, right after an action.
    • The process requires immediate updates that should be visible to the user.

3. Explain any scenario where we can use Display BR instead of using GlideAjax?

  • "Display" Business Rules are useful when:
    • You want to dynamically show or hide fields, sections, or related lists on a form based on specific conditions without a server request.
    • Display Business Rules execute their logic when a form loads and a record is loaded from the database. They must complete execution before control of the form is given to a user. The purpose of a display Business Rule is to populate an automatically instantiated object, g_scratchpad. The g_scratchpad object is passed from the display Business Rule to the client-side for use by client-side scripts. Recall that when scripting on the client-side, scripts only have access to fields and field values for fields on the form and not all of the fields from the database. Use the g_scratchpad object to pass data to the client-side without modifying the form. The g_scratchpad object has no default properties.

      Type Use case
    • Display Business Rule in ServiceNow:
      Code written in display business rule get executed before the form is presented to the user and just after the data is read from the database.

      For e.g. you have written the code that when xyz user click on information box then only data related to that user specific country will get displayed to user. It means that user from US can see US specific data and user from India can see India specific data.


      Before Business Rule in ServiceNow:
      Code written in before business rule get executed when user submits the form and data is not saved in database.
      Let’s say User click on submit button --> Before business rule code executes --> information will save in database.

      For e.g. Let’s say you have written the code that when user click on submit button then some extra information which in not filled by user such as user current location, user manager name and user past activities will get save when user click on submit button.

      After Business Rule in ServiceNow:
      Code written in after business rule get executed when user submits the form and data saved in database.
      Let’s say User click on submit button --> data saved in database --> Now after business rule code get executed.

      For e.g. there is parent incident and child incident and you want that related child incident will get closed automatically after the parent incident get closed by user.


      Async Business Rule in ServiceNow:
      Async business rules are like after business rule but it runs in the background simultaneously with other processes. Means async business rule run after the data is saved into the database.
      Running on background means that use can proceed with other functionality and code will run on the background which will not impact the user while doing other transitions.

      For e.g. Incident ticket is in pending customer action status and will be auto closed after 5 days if user did not provide any update on incident ticket.

       

    •  
    • displayUse to provide client-side scripts access to server-side data.
      beforeUse to update information on the current object. For example, a business rule containing current.state=3; would set the State field on the current record to the state with a value of 3.
      afterUse to update information on related objects that need to be displayed immediately, such as GlideRecord queries.
      asyncUse to update information on related objects that do not need to be displayed immediately, such as calculating metrics and SLAs.

Please mark it as helpful if its works so it can benefit the community.
Thanks,

Abin. 

View solution in original post

9 REPLIES 9

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @sagarpundir

 

Nowadays, interviews are conducted at different levels, which means it’s difficult to predict what might be asked. It could be something you already know or even an issue the interviewer has faced.

Instead of just focusing on scenarios, I’d suggest strengthening your fundamentals and basics of important scripting concepts. Spend time revising and brushing up those concepts on different platforms like the Developer Site, community forums, and YouTube videos

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Nikhil Bajaj9
Giga Sage

Hi @sagarpundir ,

 

You need to learn these concepts and do the practical. You should start with javascript and then go for SN scripting part. You can refer few yourtube channels like:-

 

1) Learn SN with Ravi

2) ServiceNow India 

 

Once you will learn and work on few real time scenarios then you will be able to answer these questions on interviews.

 

If my answer helepd you, please mark it- solution accepted. 

 

Regards,

Nikhil Bajaj

 

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @sagarpundir 

 

https://developer.servicenow.com/dev.do#!/learn/courses/yokohama/app_store_learnv2_scripting_yokoham...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Pradeep Thipani
Mega Sage

Hi @sagarpundir ,

 

Please practice the scenario-based questions listed below. In addition, I recommend strengthening your understanding of the stories you have developed so far. Don’t limit yourself to the same scenarios try modifying the requirements and practicing around them so you become more familiar and confident.

 

https://www.servicenow.com/community/itsm-forum/can-anyone-share-interview-questions-and-scenarios-i...

https://www.servicenow.com/community/developer-forum/business-rule-interview-questions/m-p/2688425

https://interviewquestions.guru/servicenow-scenario-based-interview-questions/

 

 

Thanks,

Pradeep

 

 

 

"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep