LogiUpSkill

Domain Separation In Service-now

Domain Separation In Service-now  1. MSP –Managed Service Providers  2. It is a paid plugin, user needs a Maint Role to activate the plugin in your instance.  3. It is a logically defined entity used to             1. Separate Data             2. Separate Process             3. Administrative Tasks   4. MSP deals with which user can see and access what data   5. By structure Service now has a Single Tenant Architecture but by using MSP plugin it can be used as Multi-Tenant Architecture   6. Multi-Tenant: It is a structure of application where single instance of the application serves multiple customers by sharing the application properties and a single database.   7. Service now with MSP Plugin:                1. Service now with MSP  Plugin acts as a Multi-Tenant architecture where single instance serves multiple customers using single database.                2. Each customer data is isolated and remains invisible to other customers.   8. When we should not go with MSP Plugins-              1. In case of total separation of all system properties              2. Does not require the global reporting              3. Does not require a single global processes   9. System will not support the following tables from being domain Separated                Access Control [sys_security_acl]                Script Includes [sys_script_include]                System Property [sys_properties]                Dictionary Entry [sys_dictionary]               Dictionary Entry Override [sys_dictionary_override]  10. Domain Scope:        Domain scope defines what users can(data) and cannot access(data) and how(Process).             1. Session Scope Domain             2. Record Scope Domain             1. Session Scope Domain:                           a. User Domain                             b. User domain Picker Domain                          Session domain of users is nothing but the user record domain if we have the user domain and the domain picket domain is the same in case of not,                                       session domain is the same like the domain which use has selected from domain picker.                         Users from parent domain they can change their session domain by changing from Domain picker.   2. Record Scope Domain:               a. It is nothing but the domain of that targeted record.               By Default the record scope take precedence over the session scope   11. We have following domains which has some special meanings.                Global Domain:               a. All the records which we have before enabling the MSP plugin, are part of global domain.               b. Guest user is a part of global.  Default Domain:                a. We can set any domain as a default domain but only one can be a default domain.                b. If you set default domain in an instance, instance will replace the global domain with default domain whenever the record creation happens. Primary Domain:              a. Only the domain which does not have parent can be set as primary domain.

Table Names in Service-now

Table Names in Service-now Users – sys_user Roles – sys_user_role Group – sys_user_group Contains Roles – sys_user_role_contains UserRole mapping – sys_user_has_role GroupMember – sys_user_grmember Application menu – sys_app_application Modules – sys_app_module Choice – sys_choice Business Rules – sys_script UI Actions – sys_ui_action Client Script – sys_script_client Plugins – v_plugins Syntax Editor macros – syntax_editor_macro Dictionary Entries – sys_dictionary Tables – sys_db_object Remote Instance – sys_update_set_source Retrieved Update Sets – sys_remote_update_set Update Set Log – sys_update_set_log Local Update Set – sys_update_set Incident – incident Task – task Problem – problem Change request – change_request Field Classes – sys_glide_object Form Sections or Layouts  – sys_ui_section Views – sys_ui_view Dictionary Entry Override – sys_dictionary_override Request – sc_request Catalog Item – sc_cat_item Requested Item – sc_req_item Catalog Task – sc_task

View Rule

View Rule This rule determines how a record is presented to the user by dynamically selecting the appropriate view based on defined conditions. Instead of showing the same layout to everyone, it intelligently adapts the form view according to factors such as user role, record state, or field values.  By doing so, it ensures that:  Users see only the most relevant fields  The interface remains clean, focused, and role-specific  Data entry becomes faster and less error-prone  Overall user experience is more intuitive and efficient  In short, this rule acts as a smart filter for the UI, displaying the right view at the right time to the right user—enhancing clarity, productivity, and usability.  To create a view, go to Configure → All → View Rules and click New.  A form will open where you define conditions to control which view is shown. Based on these conditions, the system automatically displays the most relevant view, ensuring a clean and user-friendly interface.  Save the form to apply the configuration.  Once saved, the View Rule is created and stored as shown below, ready to dynamically control which view is displayed based on the defined conditions.  Now, based on the conditions defined in the View Rule, open any Incident record where the Caller is Mac Marksberry.  When you open this record, the system will automatically apply the rule and display the configured view for that condition.  As per the configured View Rule, the record will now be displayed in the ESS (Self-Service) View.  This means the Incident opens in the Self-Service View, showing only the relevant fields intended for end users, as illustrated below.  We can also create a View Rule using a script by enabling the Advanced checkbox.  This allows you to apply custom scripted logic to determine the view dynamically, offering greater flexibility for complex conditions beyond the standard configuration. 

Data Policy

Data Policy Definition: A Data Policy is a server-side rule that enforces data consistency and integrity by setting fields to mandatory or read-only based on specified conditions. It applies to all data entry methods, ensuring rules are followed regardless of how records are created or updated. Web services/APIs Import sets Email integrations Mobile UI Scripted updates Steps to create Data Policy: Navigate to the Application Menu, search for Data Policies, and select Data Policies under the System Policy After clicking this, we are redirected to the form shown below, where the next set of configurations can be performed. Here is short description about checkboxes that are present on the Data Policy form: Use as UI Policy on client – Applies the Data Policy on the client side like a UI Policy, without writing scripts. InheritWhen enabled, this UI Policy is inherited by child tables of the current table. If unchecked, the policy applies only to the current table. Reverse if falseAutomatically reverses the UI Policy actions when the condition becomes false. This ensures fields return to their original state without needing extra logic. Apply to import setsApplies the UI Policy during data imports via Import Sets. Useful when you want the same rules enforced on imported records. Apply to SOAPEnsures the UI Policy is applied when records are created or updated through SOAP web services. Example: When Data Policy is applied to a field, it is enforced even during data imports from external sources. While importing data, the system checks whether a Data Policy exists on the target table and field. If the imported value violates the policy (for example, a mandatory field is left empty), the record will not be inserted or updated.This ensures data consistency and validation, regardless of whether the data is entered manually or imported. To implement this requirement, we create a table called User Details. In this example, we apply Data Policy on a field to enforce validation, as shown in the screenshot above. In the next step, we import anonymous data from an external source like Excel to validate the applied Data Policy. Navigate to the Application Menu and search for Load Data to begin the import process. Select the Create Table option, then click Choose File to upload the source file. Once the data file upload is complete, this page appears to continue the import process This means your data has been uploaded and is ready for the next step. We attempted to upload 10 records from the Excel file; however, only 8 records were successfully uploaded due to validation rules. This happens because of the applied Data Policy. The Data Policy is enforced on the Mother Name field, and in the imported data, the last two rows don’t have values for this field. As a result, those records fail to the Data Policy validation and are not imported, while the remaining records are successfully accepted.

JavaScript Overview

JavaScript Overview JavaScript Output: We have the following ways to display output in JavaScript: innerHTML – displays data inside an HTML element <p id=”demo”></p> <script> document.getElementById(“demo”).innerHTML = 1 + 0; </script>   document.write() – mostly used for testing document.write(“Pavan”);   Button with document.write() – removes all HTML and shows only output <button type=”button” onclick=”document.write(‘Pavan’)”>Click</button>   window.alert() – shows data in alert box window.alert(“Pavan”);   console.log() – used for debugging console.log(“Pavan”); Instructions: Programming means giving instructions to the machine. Instructions are written as statements. JavaScript executes statements from top to bottom. Statements may contain values, operators, expressions, comments, and keywords. Semicolon (;) ends a statement. Example var x = 10; var y = 20; var z = x + y; We can break a line after an operator: var total = x + y; Keywords: Some important JavaScript keywords:break, continue, debugger, do…while, for,function, if…else, return, switch, try…catch Syntax: var KeywordThe var keyword tells the browser to create a variable in JavaScript. ValuesThere are two types of values in JavaScript:1. Literals (Fixed Values)These are hardcoded or constant values.10“Pavan”true 2. Variables (Stored Values)These values are stored in variables.var name = “Pavan”; Case Sensitivity:JavaScript is case-sensitive, meaning variable names with different cases are treated as different variables. var lastname = “A”;var Lastname = “B”; // Both are different variables Variable Declarations:You can declare variables in different ways: var y; // Declared but undefinedvar f, g, h; // Multiple variable declaration String Concatenation ExampleUsing the + operator to combine strings:g = “P” + “a”; // Result: “Pa”f = g + “van”; // Result: “Pavan” Variables: Variables store data values. Variable names must be unique. Variables declared without var are global. Variable Rules: Can contain letters, digits, _, $Must start with a letterCase-sensitiveCannot use reserved keywordsvar x; // value is undefined Types of Variables: Types of Variables:1. Local Variable – accessible within a block function test() {var x = 10;} 2. Global Variable – accessible throughout the pagevar y = 20; Operators: = is the assignment operator and == is the equal operator  ++ increment  — decrement  null === undefined // false null == undefined //true  () operator invokes the function  Notes: myFunction; // returns function definitionmyFunction(); // returns function result Data Type: Primitive Data Type (normal data types which are without properties and methods):  String Number Bolean Undefined Null  Non-Primitive Data Types:  Object Array RegExp  typeof undefined // undefined typeof null // object  Function: for reusability of code  We invoke the function on  any event occurs (on click of user)  () from JavaScript code  Automatically (self-invoked)  Events: onChange  onClick  onMouseover  onMouseout  onKeydown  onLoad  Object: var training = {trainername: “Abel”,skill: “ServiceNow”,id: 111,trainerwithskill: function() {return this.trainername + ” ” + this.skill;}}; var t1 = training.trainerwithskill(); // function valuevar t2 = training.trainerwithskill; // function definitionvar t3 = training.skill;var t4 = training[“skill”]; JavaScript Looping examples: If-else:  if (a < 1) { skill = “Java”; } else if (a < 2) { skill = “PHP”; } else { skill = “Servicenow”; }  For loop:  Example 1  for (i = 1; i < 5; i++) { text += “Servicenow chapter ” + i + ” “; }  Example 2 j=1; for (; j < 5; j++) { text += “Servicenow chapter ” + i + ” “; }  Example 3  var trainer = {name:”Pavan”, skill:”Java”, age:28};  var text = “”; var x; for (x in trainer) { text += trainer[x]; }  Example 4 var txt = “”; var trainer = [{name:”Pavan”, skill:”Java”, age:28},{name:”Paavan”, skill:”Java”, age:28}];  var x; for (x in trainer) { txt += trainer[x][“name”]; }  document.getElementById(“demo”).innerHTML = txt;   Switch:  switch (new Date().getDay()) { case 0: day = “Today is Sunday”; break; case 1: day = “Today is Today is Monday”; break; case 2: day = “Today is Tuesday”; break; case 3: day = “Today is Wednesday”; break; case 4: day = “Today is Thursday”; break; case 5: day = “Today is Friday”; break; case 6: day = “Today is Saturday”; break; default: day = “No Default”; }  while loop:  while (i < 10) { text += “The number is ” + i; i++; }  do while loop:  do { text += “The number is ” + i; i++; } while (i < 10);  JavaScript Function: function is an Object in JavaScript  JavaScript function has properties as well as methods.  Normal Functionfunction myFunction(a, b) {return a * b;}var x = myFunction(4, 3); Anonymous Functionvar pp = function() {alert(“Hi this is anonymous function”);}; Constructor Functionfunction Member(a, b) {this.name = a;this.skill = b;}var t = new Member(“Pavan”, “ServiceNow”);var g = new Member(“Pankaj”, “Java”); Arrow Function// ES5var x = function(p, q) {return p * q;};// ES6const x = (p, q) => p * q; Callback FunctionA callback function is a function passed as an argument to another function. function p1(x) {return x;}function p2(b, callback) {callback(b);}p2(2, p1);p2(3, function() {alert(“Hi”);});

Service Portal

Service Portal Basic Widget in Service-now Service Portal is a powerful framework for building self-service websites and custom web app UIs. Using a hierarchy of table driven components, Service Portal simplifies the process and reduces the code required to build a web interface. With Service Portal, you can deliver your apps to employees through a modern, easy to use portal they can access from any device, any time. To create a service portal, navigate to Service Portal => portals => New button, the following form will be displayed, Enter Title , URL suffix (used to run the service portal in the browser) as shown in above form. To run this portal,write URL suffix at the end of the current instance URL as below, Page Pages control where and how you store portal content. To create page navigate to Service Portal => Pages and click on New Button to create a page. The following form will be displayed , Enter the title ,Id for the page and save the changes. After creating this page,At the bottom click on “Open in Designer” link, to create the content on the page,as below, The following “Page Designer” will be displayed on the browser , From the Widgets tab at the left , from layouts , First we need to add a container and then divide that container using a required grid to divide the space in the container. In the below snapshot we have added the container and  [6 6] grid and we have added widgets calculator and clock as a content , You can add this page to portal by following way, Open your service portal and select Homepage as the page name that we want to add. Now go to the portal by entering the URL suffix (snowtraining) at the end of the current instance URL in the browser,you will get the page that we have added as below, Menus To create Menu,navigate to Service Portal => Menus and click on New button to create the Menu as below, How this Menu should appear on the page we can select in widget, For example , below,Training Menu should appear as Header Menu on a page so select “Header Menu” as Widget as below, Save above Menu. Add Menu Item by clicking “New” button from “Menu Item” section at the bottom as below, Create Menu item as shown in below screenshot, As shown in above screenshot, Enter Type of Menu,Catalog item and Page for that menu Type : Catalog Item Page : this decides where to display catalog item, “sc_cat_item”  is used to display catalog item. You can add these above Menu to the service portal by selecting the Menu as below, Service Portal Configuration Branding Editor :  Used to customize the portal’s title,logo and theme colors. Navigate to Service Portal => Service Portal Configurator as below,  The following configuration page will be displayed in the browser, Click on Branding Editor,to customize portal’s title,logo and theme colors. The following page will be displayed, Simple List example : Create a page to display a list of incidents and problems using Simple List widget. ’  Click on Open in Designer to design a page,  Drag and drop 2 containers and divide them using grid as below, Drag and Drop a Simple List widget into Container 1 as follows, Click on pencil to edit the list,following window will be displayed, Configure 2nd simple list for Problem table as below, We can link this page to Menu. Create one menu and link the above page(tr_incident) to it as follows, Save the above Menu and go to the portal,you can see the Menu named as Ticket that we have  just created as follows, Click on that Ticket Menu,the list of incident and problem will be displayed as follows, If you click on any incident ,the following page will be displayed in which we can only write the issues.,because on the page we have set Link Type as Ticket., Click on any Problem, The form will be displayed as follows because on page we have set Link Type as Form. Add Search on Homepage : We can use existing instances on a page. For example , Use “Search” from the below Service Portal to our Service Portal , For that ,open Service Portal and check which instance is used for displaying “Search” on Homepage  in this service portal, Open a Record of Homepage to know the instance as follows, The following Page will be displayed and you can see the “Homepage Search” instance is used to display the Search on HomePage. Now,Open our homepage in design mode and add one container at the top and drag and drop “HomePage Search”in that container as below, Navigate to our portal by entering our developer instance URL with suffix snowtraining ,the “Search” will be displayed as follows, Design Page without Designer: You can design a page directly on the page without using Designer. For that ,open a page ,at the bottom there is a list of containers. Create a new container by clicking on New button, At the bottom, Click on Column 1 of newly created container as below, At the bottom click on New button to create the instance , Widget Data Table : Class – Instance with Table Here you can add widget,take data table as a widget as follows, When you use the Data table as a widget,you need to select a table. For that first Select “Instance with Table” as a Class, (if class field is not available on the form then display it from Form Layout =>Slush Bucket) Save it and then you will get some more fields on the form where you can select a table as below, Display Icon : To display icon,select “Icon Link” as a widget and Class “Instance with Link”, Save the above form. Now, After clicking on that icon,we need to select what should be displayed,as below, Navigate to Service Portal URL, you will see the Icon which we have created

Update Sets in Service-now

Update Sets in Service-now Update Sets 1. Update sets are used to capture the configuration data of a table. Update sets can be used to migrate the configuration data that has been done from one instance to another instance (example: from developer instance to test instance).   Configuration Data- Creating tables, fields, business rules, client scripts, choices etc. Normally we will consider the data in system tables, we consider as a configuration data.Normal Data: Creating records in incident, problem, user tables. Update_Synch table attribute 2. The tables for which UPDATE SYNCH attribute value will be true only for those tables the configuration data will be captured. 3. Since XML import and export can be used to migrate only one entry at a time, hence we use update sets which are capable of migrating the configuration records of multiple table at same time. 4. To create update setsGo to navigation -> update sets -> local update set -> new  Difference between Submit and Submit and make current: If we want to create the update set we can use the submit button but if we use submit and make current that update set will be created and will be made current i.e it will capture the modifications from that point of time.  Retrieved Update set: To obtain the captured information from other users update sets we can use this option. Steps: -> Go to update source in navigation search -> New -> Enter the values in fields – >Name: Other users update set name. – >URL: other users URL – >Username and Password: Other User’s credentials  Preview update set : To check whether the update set have been retried successfully or not.If successfully retrieved we can commit the changes and if there are any other errors it has to be rectified before the commit option can be used. …………………………………………………………………………………………………………………………………………….. Customer are not able to add the update_synch attribute on custom table, seems like user need to contact Servicenow only.

GlideDate in Servicenow

GlideDate in Servicenow gs.print(new GlideDateTime(“2011-08-01 12:00:00”).getDate()); var tt=new GlideDateTime().getDate();gs.print(tt); var ss=new GlideDateTime(“2017-11-04 12:00:00”).getDate();gs.print(ss); gs.print(Date()); …………………………………………………………………………. var g = new GlideDate();g.setValue(‘2015-01-01’);gs.info(g); var gDT = new GlideDateTime(g);gs.info(gDT); ……………………………………………………………………………………………………………. var gdt1 = new GlideDateTime(“2016-05-15”);var gdt2 = new GlideDateTime(gs.now());var dur = new GlideDuration(); var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2var temp = dur.getDisplayValue()gs.print(temp); var r= parseInt(temp);if(r==30 || r==60 || r==90){gs.print(“trigger”);}else{gs.print(“no”);} ……………………………………………………………………………………………………………………………………..   var gr = new GlideRecord(‘incident’);gr.get(‘784b900d4f4533001a0f45dba310c713’);var open= gr.opened_at;var gdt = new GlideDateTime(open);gdt.addDays(14);var due_date = gdt; gs.print(“Due Date After 14 days”+due_date); gs.print(“Numaric value for Open date”+gr.opened_at.dateNumericValue());   gs.print(“Open Date”+gr.opened_at); var tempp=gr.opened_at.dateNumericValue()+ 60000; gs.print(“final numaric value”+tempp); gr.opened_at.setDateNumericValue(tempp); gs.print(“Addding 60000 to Open date”+gr.opened_at.getValue());   ……………………………………………………………………………………………………………… var gdt1 = new GlideDateTime(“2019-04-24”); gs.print(gdt1); var gtime1 = new GlideTime();gtime1.setValue(“00:00:20”);gdt1.add(gtime1); gs.print(gdt1);   ………………………………………………………………………………………………………………………….. Javascript will not able give you the result without using time function var a = new Date(‘2013-11-05’);var b = new Date(‘2013-11-05’); if(a == b) {console.info(“a equals b”);}else {console.log(“a NOT equals b”);} if(a.getTime() == b.getTime()) {console.info(“a equals b”);}else {console.log(“a NOT equals b”);}

Workflow

Sub – Workflow Workflow is series of activities that follows execution path. An Activity is a collection of instructions that can include script, logging, approvals, record processing, timers, wait time, rollback activity etc. To create a workflow we need to go for workflow editor and we can drag and drop required activity in workflow. We can also drag and drop any other workflow in current workflow. We can create scratchpad variable to pass values from one activity to another. If we are using If activity then we can specify condition as follows- Following is the main workflow and we have added one sub workflow in main workflow. Sub Workflow- To send data from main workflow to sub workflow we need to create one input variable in sub workflow to hold value coming from main workflow as follows- We can specify input filed name, type, length etc as follows- Create scratchpad variable in main workflow Set value coming from main workflow to input variable Trainer Course To access value coming in input variable assign it to some other filed like short description To test this run the catalog item. Add Trainer name as Meghana. then automatically data present is scratchpad variable will be passed to sub workflow. After providing approval, check the workflow. short description should hold data coming from main workflow i.e. Service Now.   To send data back from sub workflow to main workflow we need to create scratchpad variable in sub workflow as follows – Then need to create return activity as follows and specify scratchpad variable as ${workflow.scratchpad.cost} Now go to main workflow and set map return value to as follows-   Then assign the value coming from sub workflow to description filed as follows, Main Workflow- Sub Workflow – Result- Incident Workflow Assignment Create Following Group’s 1.Email Group2.Phone Group3.Self Group4.Walk_in Group Create new state for Incident state field i.e. Waiting for Approval Incident Workflow         |         | Wait till the asigned to field should get value         |set state=Waiting for Approval         |         |Go for the approval according to Contact Type 1.Email ——Email Group2.Phone ——Group3.Self ——–Group4.Walk_in ——Group Any approval reject, it will go to run script activity where we should change the state=Canceled and then end the workflowAfter Approval         |         |         |Another approval should get trigger to Incident’s Caller’s ManagerIF the it reject , it will roll back to again the previous group approvalAfter approval it will go further         |         |         |Change the state=In Progress         |         |         |After this there should be 2 parallel process.1. if user canceled or closed the incident,then the workflow should end.2. if user changed the priority then put comments as “Priority changed” and go to Activity of Caller’s Manager Approval. but this priority changes can be done 2 times, if user is trying to do it for 3 times, then change the state=resolvedand end the workflow. Incident Form Field Task 1.Contact type field should have default value=Self Service2.User should not change the contact type field value once he submit the form3.User should not submit the form without categoy and subcategory field values Branch and Join        Branch flow Activity: The Branch activity is used to run the two activities parallel. The Branchactivity splits the workflow into multiple transition paths from a single activity. To add a transition path, select and drag the Branchactivity into the canvas. Then you can see the Branch activityproperties form displays, enter the branch name and click Submit to add the activity to the canvas, then click AddCondition. All transitions from this activity execute concurrently. This activity provides a single Always You can execute any number of transitions from this condition. Branching can affect the behavior of rollback activities.              Join flow Activity: The Join activity combines multiple execution paths into one transition path. To add Join to the canvas, Drag the join into the canvas and enter the name of join in the properties screenand click Submit. Use this activity for a workflow to wait for all activities in multiple paths to finish before it continuing. If multiple concurrentworkflow paths meet without a join activity, any subsequent activities execute two times. Connect incoming transitions from each activity you want to act as a predecessor to the Join activity. There will be two exit condition for the outgoing transitions: Complete and Incomplete. Complete: Joinexits along the Complete path when the system has determined that all predecessor activities havecompleted and transitioned to the Join. Incomplete: Joinexits along the Incomplete path when the system determines that at least one predecessor activitycompleted but transitioned along a path that bypassed the Join              Example: We have to set values for short description and description parallel when the wait for condition is true ->For that weuse Branch to run the two activity concurrently. We have to join two activity for approval user and approval group is approved then both condition satisfy it go toend -> For that we use Join to join that two activities.              Create Branch              Setting the values parallel for branch              Create approval user and group for join the activities              Create Join for two activities are approval user and approval group              Workflow for join and branch:              Output:              Branch output set the values for short description and description              Join output:              Once the user and group are approved the join go to end              Incomplete Join:              Usecase1:              If both approval user and approval group are approved then it show as complete. If approval user is approved and approval              group is rejected then it go as incomplete state.                Output for incomplete join:              Reject the approval for approval group and approved the approval user              Now it is in incomplete state then it go to end              If it is both are approved then it make as complete and go to end:              Usecase2:              If approval user is approved and approval group is rejected then it go incomplete then rollback condition

Server Side Script

Glide Aggregate – Scripting 1. To find no of records in table var g= new GlideAggregate(‘incident’); g.addAggregate(‘COUNT’); g.query(); var incident= 0; if(g.next()){ incident= g.getAggregate(“COUNT”); } gs.print(‘The Number of incidents are=’+incident); 2. To find no of incidents with caller Pallavi using addEncodedQuery var g= new GlideAggregate(‘incident’); g.addEncodedQuery(‘caller_id=681ccaf9c0a8016400b98a06818d57c7’);//Sys_id of Pallavi g.addAggregate(‘COUNT’); g.query(); var incident=0; if(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘Number of incidents with caller Pallavi=’+incident); 3. To find no of incidents where assigned to field is not empty var g=new GlideAggregate(‘incident’); g.addNotNullQuery(‘assigned_to’); g.addAggregate(‘COUNT’); g.query(); var incident=0; while(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘number of incident where assigned to field is not empty=’+incident); 4. To find no of incidents where assigned to field is empty var g=new GlideAggregate(‘incident’); g.addNullQuery(‘assigned_to’); g.addAggregate(‘COUNT’); g.query(); var incident=0; while(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘number of incident where assigned to field is empty=’+incident); 5. To find number of incidents with state new var g=new GlideAggregate(‘incident’); g.addQuery(‘state’, ‘1’); g.addAggregate(‘COUNT’); g.query(); var incident=0; while(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘number of incident with state new=’+incident); 6. To find number of incidents active true var g=new GlideAggregate(‘incident’); g.addQuery(‘active’, ‘true’); g.addAggregate(‘COUNT’); g.query(); var incident=0; while(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘number of incidents=’+incident); 7. To find no of incidents with different category var g =new GlideAggregate(‘incident’); g.addQuery(‘active’,’true’); g.addAggregate(‘COUNT’,’category’); g.query(); while(g.next()){ category = g.category; categoryCount = g.getAggregate(‘COUNT’,’category’); } gs.log(“The are currently “+ categoryCount +” incidents with a category of “+ category);lideAggregate(‘incident’); g.addAggregate(‘COUNT’); g.query(); var incident= 0; if(g.next()){ incident= g.getAggregate(“COUNT”); } gs.print(‘The Number of incidents are=’+incident); 8. To find no of incidents with caller Pallavi using addEncodedQuery var g= new GlideAggregate(‘incident’); g.addEncodedQuery(‘caller_id=681ccaf9c0a8016400b98a06818d57c7’);//Sys_id of Pallavi g.addAggregate(‘COUNT’); g.query(); var incident=0; if(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘Number of incidents with caller Pallavi=’+incident); 9. To find no of incidents where assigned to field is not empty var g=new GlideAggregate(‘incident’); g.addNotNullQuery(‘assigned_to’); g.addAggregate(‘COUNT’); g.query(); var incident=0; while(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘number of incident where assigned to field is not empty=’+incident); 10. To find no of incidents where assigned to field is empty var g=new GlideAggregate(‘incident’); g.addNullQuery(‘assigned_to’); g.addAggregate(‘COUNT’); g.query(); var incident=0; while(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘number of incident where assigned to field is empty=’+incident); 11. To find number of incidents with state new var g=new GlideAggregate(‘incident’); g.addQuery(‘state’, ‘1’); g.addAggregate(‘COUNT’); g.query(); var incident=0; while(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘number of incident with state new=’+incident); 12. To find number of incidents active true var g=new GlideAggregate(‘incident’); g.addQuery(‘active’, ‘true’); g.addAggregate(‘COUNT’); g.query(); var incident=0; while(g.next()){ incident=g.getAggregate(‘COUNT’); } gs.print(‘number of incidents=’+incident); 13. To find no of incidents with different category var g =new GlideAggregate(‘incident’); g.addQuery(‘active’,’true’); g.addAggregate(‘COUNT’,’category’); g.query(); while(g.next()){ category = g.category; categoryCount = g.getAggregate(‘COUNT’,’category’); } gs.log(“The are currently “+ categoryCount +” incidents with a category of “+ category); Glide Record – Scripting 1. To find out number of active incidents var incident=new GlideRecord(‘incident’); incident.addQuery(‘active’, ‘true’); incident.query(); gs.print(“Row count =”+incident.getRowCount()); 2. To find out list of active incidents var incident=new GlideRecord(‘incident’); incident.addQuery(‘active’, ‘true’); incident.query(); gs.print(“Row count =”+incident.getRowCount()); gs.print(“List of Incidents”); while(incident.next()){ gs.print(‘Incident number’+incident.number); } 3. To find out no of incidents assigned to admin userid var gr= new GlideRecord(“incident”); var p= gs.getUserID(“admin”); gr.addQuery(“assigned_to”,p); gr.query(); gs.print(“No of incidents=”+gr.getRowCount()); while(gr.next()){ gs.print(gr.number); } 4. To find out no of incidents assigned to current user var gr= new GlideRecord(“incident”); var p= gs.getUserID(); gr.addQuery(“assigned_to”,p); gr.query(); gs.print(“No of incidents=”+gr.getRowCount()); while(gr.next()){ gs.print(gr.number); } 5. How many incidents with category hardware? var g= new GlideRecord(“incident”); g.addQuery(“category”,”hardware”); g.query(); gs.print(“No of incidents with category hardware=”+g.getRowCount()); while(g.next()){ gs.print(g.number); } 6. How many incidents with “Assigned To” value contains name admin? var gr=new GlideRecord(‘incident’); gr.addQuery(‘assigned_to.name’,’CONTAINS’,’admin’); gr.query(); var a= gr.getRowCount(); gs.print(a); while(gr.next){ gs.print(gr.number); } 7. Get all the incident which has Assigned to user having first name contains name admin word var gr= new GlideRecord(‘incident’); //gr.addEncodedQuery(‘assigned_toLIKEadmin’); //gr.addEncodedQuery(‘assigned_to.first_name.admin’); gr.addEncodedQuery(‘GOTOassigned_to.first_nameLIKEadmin’); /* var user= gs.getUserName(‘admin’); var admin=gr.addQuery(‘user’,admin); gr.addQuery(‘assigned_to’,user); */ //gr.addQuery(‘assigned_to’,’CONTAINS’,’admin’); gr.query(); while(gr.next()){ var count=gr.getRowCount(); } gs.print(count);   8. To find out number incidents which are resolved or closed var incident=new GlideRecord(‘incident’); incident.addQuery(‘state’, ‘6’).addOrCondition(‘state’, ‘7’); // resolved=6 and closed=7 incident.query(); gs.print(“Row count =”+incident.getRowCount());   9. Print first 4 Incident’s where caller’s first name start with Meghana var gr =new GlideRecord(“incident”); gr.addQuery(“caller.first_name”,”STARTSWITH”,”Meghana”); gr.orderBy(‘number’); gr.chooseWindow(0, 4); gr.query(); while(gr.next()){ gs.print(gr.number) } 10. Print the incident number using sys_id var gr = new GlideRecord(‘incident’); if (gr.get(’46cd8aaa2fe318104f7fdb9df699b604′))  //Sys id of record     gs.print(gr.number);   11. Print out first 4 incidents orderby number var gr = new GlideRecord(‘incident’); gr.orderBy(‘number’); // Ascending Order gr.chooseWindow(0, 4); gr.query(); while (gr.next()) {    gs.print(gr.number); } 12. Print 10 incidents by descending order of created date var gr = new GlideRecord(‘incident’); gr.orderByDesc(‘sys_created_on’);  // this will be descending order but by default will be ascending order and  gr.setLimit(10); gr.query();     while(gr.next()){ gs.print(gr.number); }   13. Delete the records from Table var gr = new GlideRecord(“incident”); gr.addQuery(“state”,3); //to delete all inactive incidents gr.query(); gr.deleteMultiple(); var gr = new GlideRecord(“incident”); //to delete one record if (gr.get(“SYS_ID_OF_RECORD”)) gr.deleteRecord(); Business Rule and Script Include Example Script Include and Business Rule Example: Business Rule: (After Insert) (function executeRule(current, previous /*null when async*/) {var createP=new ProblemUtils();var problemSysid=createP.createProblemRecord(current); //Create a Problem var getProblemRecrod=createP.getRecrodNumber(problemSysid,”problem”);  //get Problem Number createP.updateParent(getProblemRecrod,”problem”,current); // Update problem with Parent field gs.addInfoMessage(getProblemRecrod);})(current, previous);   Script Include:(Not Client Callable) var ProblemUtils = Class.create();ProblemUtils.prototype = {initialize: function() {}, createProblemRecord:function(current){ var createProblem=new GlideRecord(“problem”); // GlideRecord API is used to Query the table, Table name=problem createProblem.initialize(); // initialization of object createProblem.short_description=current.short_description + “Assingedto:” +current.assigned_to.name; //mapping createProblem.assigned_to=current.assigned_to; ////mapping createProblem.assignment_group=current.assignment_group; //mapping createProblem.description=current.description ; //mapping var problemSysid=createProblem.insert(); return problemSysid;}, getRecrodNumber:function (sysid,tableName){ var getNumber=new GlideRecord(“”+tableName);getNumber.addQuery(“sys_id”,sysid);getNumber.query();if(getNumber.next()){return getNumber.number;}else{ return “No Record found”;} }, updateParent:function(number,tableName,current){ var getNumber=new GlideRecord(“”+tableName);getNumber.addQuery(“number”,number);getNumber.query();if(getNumber.next()){getNumber.parent=current.sys_id;getNumber.description=current.number;getNumber.update();} }, type: ‘ProblemUtils’};