50 Assignment Itsm With Solution
50 Assignment Itsm With Solution
REQUIREMENT
Calling giveRole function
function giveRole(){
have analytics_admin or analytics_viewer query the table using query method with usergr object
role.
while(usergr.next()) {
run while a loop, each time a record is processed with
var urolegr = new GlideRecord("sys_user_has_role"); usegr.next();
urolegr.addQuery("user", usergr.sys_id);
urolegr.addQuery("role.name", "IN", Create another GlideRecord object urolegr of sys_user_has_role
"analytics_admin,analytics_viewer");
table
urolegr.setLimit(1);
urolegr.query(); Add query with addquery method, filter records where role is
analytics admin and analytics viewer
Also the result filter by user sys_id which you can get from usergr
object.
giveRole function
01
in summary, for each user record, provide the user sys_id and
roles names in order to filter in the sys_user_has_role table, and
return the result with urole.query();.
if(!urolegr.next()){
urolegr.initialize();
urolegr.user = usergr.sys_id;
urolegr.setDisplayValue("role", "analytics_admin");
urolegr.insert();
} !urolegr.next() will be true if there isn't a record and will be false if
}
there is a record.
}
The goal is to assign a role to specific users within a time period, write the script which will check the conditions, make sure that all catch(ex){ gs.info(ex);} In case it is true, set values for role field. the role will be
users don't have analytics_admin or analytics_viewer role, use the the script in a scheduled script, scheduled for every hour. } analytics_admin. and insert a new record in the sys_user_has_role
table
REQUIREMENT
Before Business Rule
ServiceNow
Database
Get the numercial value for start date and end date time, store
in start and end variables
onload script
03
time when the system Get the HTML element of the icon and store
it in a variable
renders first the form function onLoad() {
and before the access
is given to the user in var icon=document.getElementById("toggleMoreOptions");
order to work with the icon.style.display='none';
form, }
Change css display style to none
onLoad Client Script is
executed Such client
script allows us to
configure forms, forms
field and field values
While the form is loading, onLoad script code will change the css style display value to none of the 3 dotted icon, the html
element id of the icon can be found by using chrome developer tool.
Group incidents by assigned to and var arr = []; creating an empty array While loop
record
system during a while loop, store the
count value in a incidentCount variable
04
// gs.info('Display the count {0}', [incidentCount]);
if incident count >1
var inc = new GlideRecord('incident'); When the incident count is more than
one, create Inc Object of the class
inc.addEncodedQuery('assigned_to=' + agg.assigned_to); GlideRecord for incident table.
Incident table query result 2
inc.query();
add encoded query with agg.assigned.to,
query incident table, here the user have Abel Tuter
more than one record assigned to him INC01
while (inc.next())
arr.push(inc.sys_id.toString()); INC02 Abel Tuter
Test the script in background to see the result }}
this while loop is inside the previous While loop inside the first while loop
loop.
REQUIREMENT
UI Macro
UI macros are scripted components in servicenow that admins can add to the user interface.
The script is written in between Jelly Tags and the ui macro can be invoked from an ui page, from
another ui macro or by defining specific attributes in a reference field.
Create a Knowledge Base article using
an UI macro See below few examples of ui macros
05 For our requirement, we will have an ui macro created next to the incident reference
field and we will take as inputs data from two other fields (Short Description and
Description) in order to create the knowledge base.
UI macro script and UI macro rendering
<?xml version="1.0" encoding="utf-8" ?>
Jelly
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide"
xmlns:j2="null" xmlns:g2="null">
gr.insert();
Dictionary Fields list view
}
insert record </script>
</j:jelly>
Incident Reference Incident Attributes
Jelly
The ui macro name is create_kb, which is a database name, mention it in the attributes field,attributes is
a dictionary field of the incident reference field, the ui macro script has the html code to render the
icon, and call a function when the ui macro is clicked,
the function will simply run a query in Kb_Knowledge base, get short description and description from
the form and insert a new record.
REQUIREMENT
Before Business Rule
ServiceNow
Database
current.setAbortAction(true);
Before the database gets updated, restrict the form submission if the state of the incident is either 2 or 3, mention the condition in the
})(current, previous);
before business rule and the script to abort the action, this br is written on insert and updates.
REQUIREMENT After Business Rule
Database updated
to non-agent , position is a custom field after the data gets updated into the
database.
After Business Rule
in the user table and the user has ITIL This is called a After Business Rule
Create myrole object of GlideRecord Class- (function executeRule(current, previous /*null when async*/) {
sys_user_has_role Table // Add your code here
07
var myrole = new GlideRecord('sys_user_has_role');
myrole.deleteRecord();
}
user table, add ITIL role to the user. update A server side code can be executed
after the data gets updated into the
database.
After Business Rule
This is called a After Business Rule
08
Create myrole object of GlideRecord Class-
sys_user_has_role Table (function executeRule(current, previous /*null when async*/) {
This requirement is a verification of field values and action taken based on the value, therefore, write an after business rule, for
updates and insert. This br will have in condition : postion is equal to agent, run a script which will get the current user and add itil
role.
REQUIREMENT
superieur than the current date time. 1 Create grInc a Glide record Object of Incident table
query
while(grInc.next()){
09
if(new GlideDateTime(gr.reached_date).getNumericValue() >= new
GlideDateTime().getNumericValue()){ While loop
gs.eventQueue('trigger.notification',grInc,grInc.assigned_to.toString()); 3
}}
compare the current time compare the current time compare the current time
and the reached time in and the reached time in and the reached time in
numerical value numerical value.... numerical value....
Event Registry
4
queue an event and notifiy queue an event and notifiy queue an event and notifiy
the assigned to ... ...
trigger.notification
Regiser an trigger.notification event for the incident table, create as well a beta notification triggerd
when the event is fire, then write a scheduled script to query the incident table for meeting the
condition above, if there are records overdue 30, 60, 90 days , generate overdue reminder from the
script, which will automaticatlly send the notifications.
Script and Diagrams for this
Notification requirement
while(grInc.next()){
if(new GlideDateTime(gr.reached_date).getNumericValue() >= new GlideDateTime().getNumericValue()){ While the system process in each record, compare the
numerical value of the current time to the reached_date
gs.eventQueue('trigger.notification',grInc,grInc.assigned_to.toString()); time, reached is a custom date field, if the reached_date is
}} bigger than the current time, queue an event
gs.eventQueue, trigger.notification event is created in the
event registry, as a parameter mention the assigned_to
string value.
Event Registry
trigger.notification
Tables and Data Import Process Key Information
REQUIREMENT
On the first load, the data source will create a staging table and load data into it. An
import set will be also created.
1 Data Source Excel ISET Record will contain info about the data load, data source, rows etc
Staging table will have the data, fields will start u_ for their database name which will
facilitate to auto map matching fields during transform map.
Staging table is a child table of an import set row table.
There is an import set with 2 columns 2 Staging Table Import set Row Table
There are many ways to import data, example xls, script.
Transform Map
10
OnBefore grAlm.addQuery("display_name", incomingAsset);
Transform Adding query with incoming asset name and query grAlm.query();
Map Script
Target Table :
alm_asset grAlm.setValue('display_name', newAssetName);
set value of newAsset Name grAlm.update();
log info asset not found variable to the name field ( log.info('Asset updated');
display_name ) }
else{
log.info('Asset not found->' + incomingAsset);
For this exercise, create an excel file sheet with some dummy data, the file should have two columns : asset name and updated asset name, for
}
asset name, use the names values available in the asset table and for updated asset name, put some text as per your wish. Create the ignore = true;
datasource, run it to have a staging table with some data, then create a transform to map data in between staging table and target table, write
the onbefore transform script to get data from staging table, then use the incoming asset name to find records in alm asset table with similar
})(source, map, log, target);
names, it there is such records, update then nw values with updated newAssetname
REQUIREMENT onChange Client Script
Yellow
ServiceNow
In problem record, hide the Notes section When a user or systems changes the value
of a field, we can run onChange client
when state is equal to '102'. When user
script.
or system
onChange Client script The script is written on a specific field.
changes a
field value
The client script is excuted once the
change is occured.
Blue
ServiceNow
11
when the state field will get a new value or current value is 102 onChange script can be called
to hide the notes tab
On load
Database Server
System is During the lapse of time when the
A Display Business
onLoad Client Script Passing the Rule can instantiate
scratchpad g_scratchpad object
object to the which can be passed
Yellow
ServiceNow client side to the client side and
it can be used in
12
client script.
Client
When user
During the lapse of time when the system
or system renders first the form and before the
onload Client script
changes a access is given to the user in order to g_scratchpad
field value work with the form, onLoad Client Script
is executed
For this requirement use a scratchpad object which will have a boolean value either true or false, if the current user is
not member of that particular assignment group it will be false, based on the scratchpad value, modify field attributes.
write a display Business Rule on Insert and update, which will have a scratchpad object, the value it will be true if the
logged in user is member of the assignement group, use the scratchpad on the client side, if the value is false, meaning
the user is not member then you set the field read only, the opposite condition will let the user access the field.
Display Business Rule
Server
Database
})(current, previous);
A Display Business
onLoad Client Script Rule can instantiate
Passing the
scratchpad g_scratchpad object
object to the which can be passed to
Yellow
ServiceNow client side the client side and it
can be used in client
script.
When user
or system Client
changes a
field value During the lapse of time when the system
onload Client script renders first the form and before the
function onLoad(){ Create a onLoad Client script on the incident table access is given to the user in order to g_scratchpad
use the scratchpad object in a onload client script work with the form, onLoad Client Script
if(g_scratchpad.isMember.toString() == 'false'){ 2 if the value is false, meaning the user is not part of is executed
g_form.setReadOnly('contact_type', true);
// add few more fields as per your requirement the group, make the contact type read only with
} setReadOnly method Such client script allows us to configure
forms, forms field and field values
Yellow
} ServiceNow
REQUIREMENT
Add 30 seconds to the current date/time and We can create a UI action to provide any of these controls:
A button on a form.
set this value to a custom date time field from A context menu item on a form that appears when you open the form context menu or right-click the form header.
A related link in a form.
13
Adding 30 seconds to the current time
current.update();
action.setRedirectURL(current);
create an ui action, it will have a script which will get the current time, add 30 seconds and then the new value to the
custom date field, the script is called whenever you click on the ui action.
REQUIREMENT
The property values of Previous object The property values of the Current
are the values for the record fields Object are the values as they exist in
when they were loaded from the the runtime environment.
The user should select only the Stage in database and before any changes
were made.
Resolved Assigned
This is the order : ->Start->Assigned->WIP->Resolved->Closed For Ex: the
user cannot select WIP before choosing Assigned as previous value for the drop Closed
down menu, he/she cannot select resolved as value before choosing wip as
previous value.
The change that you can see above can be translated in if(current.stage == 'assigned' && previous.stage != 'start'){
programming with the follwowing code current.stage == gs.addErrorMessage('You are allowed to change stage from
'assigned' && previous.stage != 'start', start being one of Start to Assigned only');
14
the stages. current.setAbortAction(true);
previous.stage current.stage
previous.stage current.stage
script.
onload script
15
onLoad Client Script is alert(today_date_time);
executed Such client script Format the date similar to the current
allows us to configure user's date format
forms, forms field and field
values
Get the current date time using a client script, format the date and alert it
515dfef .. ...
email action, the incident short the creation of email. Get the sys_id.
16
script.pdf sys_email 515dfef
Sequence of events
2 query the attachment table with sys_email sys_id, if there is a record, we can retrieve the pdf file name.
use the pdf file name and set it as value in for short description field notice it is not sys-email
but incident table for the
same record in the
attachement table
State of the Attachement table once the pdf file is attached to incident record
grAtt.query();
Adding and Querying the table with sys_id and table name
Create an inbound email action for the incident table, with the
action type record action.
REQUIREMENT
Database updated
Change the short description of a
problem ticket 30 minutes before a time A server side code can be executed
after the data gets updated into the
database.
update
17
create grPro Object of GlideRecord Class - problem table
if ( grPro.next()) {
grPro.short_description = test;
Generate Queued Event
grPro.update();
Script Action
}
Disable rec.query();
Notification Script Querying the table
rec.setValue('notification', 1);
rec.updateMultiple();
Setting disable as value for notification field and
18
update in all records
A simple script to query the sys_user table and change the notification field value to 1 and update the new value.,
REQUIREMENT
checkCondition: function(){
Filtering the table where caller id is the current user id and quering
19
if(grInc.getRowCount() > 5)
return true;
else
if conditon
return false;
there is more than 5 records there is not more than 5 records
}, return true return false
type: 'GlideUserHasRecords'
};
Create an UI Action for incident table, give it a name you want and use this line as condition
gs.hasRole('admin'&&)new GlideUserHasRecords.checkCondition();
The script include and its method will run a query in the incident table, looking for records where the loggedin is
assigned to, if there are more 5 records, it will return true , the ui action will be then visible.
The condition field in the ui action have the code line to check if the user is an admin.
REQUIREMENT
try{
var gr = new GlideRecord('incident');
20
Incident 1 Incident 3
}
}
catch(ex){
Event Registry
}
gs.info('Exception'+ex);
6
if days are equal to 30 or 60 or 90
}
Overudue.Reminder30
7
queue a overdue reminder
Regiser an Overdue.Remider30 event for the incirent table, create as well a beta notification triggerd
when the event is fire, then write a scheduled script to query the incident table for meeting the
condition above, if there are records overdue 30, 60, 90 days , genearte overdue reminder from the
script, which wll automaticatlly send the notifications.
sendEmail();
Calling sendEmail
function
}
}
}
catch(ex){
Event Registry gs.info('Exception'+ex); if days are equal to 30 or 60 or 90
}
}
Overudue.Reminder30
Function Definition
glidefunction:concat(sys_id)
form
onload script
22
when the system renders
first the form and before
the access is given to the function onLoad(){
user in order to work with
the form,
2 create name variable, store the value
if(g_form.getValue('caller_id')){
var name = g_form.getDisplayBox('caller_id').value;
onLoad Client Script is alert(name);
executed Such client script }
allows us to configure
forms, forms field and field
values 3 alert the name
}
Simple client to get the caller id and alert it, this is onload client script
23
use g_navigation.open to call a url with the
table and query as parameteres
Show only caller id groups in the assignement Assignment Group based on the output
Reference Field of the reference qualifier
group field
Short Description
Description
....
.......
24
Dictionary Override Assignment Group
Incident
Reference Qualifier -
We begin to get the user groups in
Without writing any script include, write a single code to get the user groups and render for assignement group field, a java object which is converted
the javascript in the reference qualifier of that field. javascript: 'sys_idIN' + new global.ArrayUtil().convertArray(gs.getUser().getUserByID(current.caller_id).getMyGroups());
into an array, then to the syntax
sys_idIN, this will only list all
active groups of the user.
Notification
REQUIREMENT
25
(function runMailScript(current, template, email,
email_action, event) {
To have a custom line in the email subject, create a email notification script, get the current time and add 13 days to it, then use this new Set the subject variable to the email setSubject in parameters
value in the subject line, the email notification script will be called from the notification html message body. this line will set the subject line
REQUIREMENT
Before Business Rule
ServiceNow
27
function onChange(control, oldValue, newValue,
isLoading, isTemplate) {
1 Call the script include with GlideAjax
if (isLoading || newValue === '') {
return;
}
var ga = new
onchange client script GlideAjax('JS_Watchlist_Manager');
Add two parameters - 1 method name ga.addParam('sysparm_name', 'manData');
and the caller id, here the new value ga.addParam('sysparm_subject_person',
newValue);
ga.getXML(manParse);
onchange client
script on caller id get the xml response from manParse
function, call this function to send the }
field
Write a onchange client script for the caller field, the script will get the caller id and send this value as request and get the response
function manParse(response) {
input to script include, then the si will will the user id, run a query in the sys_user table to find out the var answer =
user manager return this value to client script, the client script will receive the manager info and update response.responseXML.documentElement.getAt
tribute("answer");
this value to the caller list field. ManParse Function
if(answer){
g_form.setValue("watch_list", answer);
parse the resonse and set the value to }
watch list }
Script Include getGroup method
var AssignedGroup = Class.create();
AssignedGroup.prototype =
AssignedGroup Create grUser object of GlideRecord class - Object.extendsObject(AbstractAjaxProcessor, {
sys_user_gmember table
REQUIREMENT getGroup: function() {
getGroup
var grUser = new GlideRecord('sys_user_grmember');
grUser.addQuery('group', this.getParameter('sysparm_ag'));
2 Get the group with this getParameter and grUser.query();
query var a = '';
while (grUser.next()) {
a += ',' + grUser.user.name;
field
for each record the system is processing with
the while loop, store the user name in the a
variable
Return a
action.setRedirectURL(url);
action.setReturnURL(current);}
29
redirect url and return url
the ui action will call a script, which will have encoded url, the url is created with field names and values, see example in the
next page, redirect and return url to update information in outage form
REQUIREMENT Display Business Rule
Database Server
System is During the lapse of time when the
Yellow
ServiceNow
30 When user or
system changes
a field value onload Client script
Client
During the lapse of time when the system
renders first the form and before the
access is given to the user in order to
work with the form, onLoad Client Script
is executed
To populate the group, create display business rule, ge the loggedin user groups and assign the first group to the assignement group field, Such client script allows us to configure
to populate assigned to value on record creation, create a onload client script, check the current record is new record, then get the logged forms, forms field and field values
Yellow
in user id and set the value to assigned to field. ServiceNow
Display Business Rule
Server
Database
current.assignment_group = groups[0];
}})(current, previous);
Yellow
ServiceNow
When user
Client
or system
changes a During the lapse of time when the system
field value onload Client script renders first the form and before the
function onLoad(){ access is given to the user in order to
work with the form, onLoad Client Script
if(g_form.isNewRecord()){
is executed
2 Create a onLoad Client script on the incident table
g_form.setValue('assigned_to', g_user.userID); get the user id and assign the value to assign_to
field Such client script allows us to configure
} forms, forms field and field values
Yellow
ServiceNow
}
REQUIREMENT
onload script
31
user in order to work with be3&operation=modify&company=7de31002db3be0104d4
the form, 767e81396194c&record_sys_id=78726b201bcffc908afeca6
5624bcb7c';
onLoad Client Script is
executed Such client script Get the record sys_id with URLSearch Params var value = new URLSearchParams(url).get('record_sys_id');
allows us to configure
forms, forms field and field alert(value);
values
Good To Know :
onLoad Client Script
User URLSearchParams class to get specific values from a string, try this code on onload client script.
32
This script runs when a
particular value define a final date variable and the if(endDate.getTime() > finalDate.getTime()){
value 2099-12-31
alert('Please give end date before 31st Dec 2099');
g_form.clearValue('u_end_date');}}
Write onchange client script for end date custom date field for the incident table, define end date variable and
get the value from newValue, define final date variable , set a 2099-12-31 as value in the parameter, compare
end date to final date, if it is bigger, alert error message and clear value for the end date field
ServiceNow
Database
current.setAbortAction(true);
}})(current, previous);
For this requirement, write a rule before database update, on record creation and updates, if the start date is superior than Abort the current action
end date, it will abort the action
REQUIREMENT
Substract 3 days to a date field in the Script and Diagrams for this requirement
incident form with a script Create grInc object of GlideRecord Class table incident
34
var date = new GlideDateTime(grInc.u_closed_date);
date.addDaysUTC(-3);
grInc.setValue('u_updated_date',date.getValue());
grInc.update(); for each record processed by the systeme during the while
loop, store in the date variable the u_closed_date time,
} substract 3 days, then set this value to u_updated field
and update
Write a server script which will get values from a custom date field (u_closed_date) and substract three days, then
set this value to another custom date field, updated date field, test this script in the background script for a specific
incident.
REQUIREMENT onchange Client Script
35
if length is more than 3. get all values of kb_list if( length>3){
field in a list array, you can then splice the list
var list = g_form.getValue('u_kb_list').toString().split(',');
array and delete the fourth element if it is list.splice(3,1);
selected by the user. g_form.setValue('u_kb_list',list);
set the values for kb_list field with the values
alert("not allowed");}
available in the list array.
}
36
grInc.addEncodedQuery('state=2');
grInc.query();
Query active record with the state in Progress
grInc.next();
while(grInc.next()){
grInc.deleteRecord();}
Write a background script, begin first to query all active records with the state in progress and then
delete it.
REQUIREMENT
script count.groupBy('assignment_group');
count.addAggregate("COUNT");
Group By assignment group and with groupBy method and count,
count.query();
and then query, this is giving a filtered list of incidents by
while (count.next()) { assignment group and their count. ex hardware 13
37
var category = count.assignment_group.getDisplayValue();
Write a script which will filter all incidents by group and count the number record for each group.
REQUIREMENT
incident form
onload script
38
user in order to work with
the form,
Hide paper clip icon with a onload client script for the incident table
REQUIREMENT
If a logged in user is member of any of those 5 CAB Approval CAB Approval Other Groups
Network Network
39
Other Groups Other Groups
Example of expected result, a user part of helpdesk, one of the five groups, he/she can see all groups including
those five, on the contrary a user who is not part of the five groups can only see all other groups and not those 5
groups.
Rendering specific Groups in the assignment group
field based on reference qualifier
checkGroup: function(){
Description
.... checkGroup(); Method
for each record processed by the system during the while loop, set
empty values for the query variable , else set nameNOTIN"+groups,
Reference Qualifier - for the query variable, return the query variable.
When query is empty, it will all groups including those 5 groups, when
javascript: new GlideGroup().checkroups();
the query is returned with nameNOTIN+ groups, it will exclued those 5
groups from list.
confirgure the dictionayr field, check the Override Reference
Qualifier and call the Script include from RQ
Override the reference qualifier for the assignment group field, the reference qualifier will call a script include and its method,
the script will run a query on the user group member table to filter members part of those 5 groups, if there is a user , the code
will return an empty value, therefore the assignement group will list all the groups, if the loggedin user is not part of this group, it
will return NameNOTIN + groups, which will list all groups and exclude those 5 groups.
REQUIREMENT
1
function sendEmail(){
gr.addActiveQuery();
gr.query();while (gr.next()) {
Notifcation is sent when
var gdStart = new GlideDateTime(gr.sys_created_on);
3 usergr.query();
}}
giveRole function
5urolegr is a GlideRecord
Object of sys_user_has_role urolegr is a GlideRecord urolegr is a GlideRecord
gs.info("Job run completed::" + new GlideDateTime()); Table Object ... Object ...
40
}
catch(ex){
gs.info('Exception'+ex);
6
Adding Query
Event Registry
}}
reached90.days 7
!urolegr .next()==true
urolegr .next()==true
sendEmail();
Calling giveRole
function
function sendEmail(){
try{
grcase.addActiveQuery();
grcase.query();
Notifcation is sent when while (grcase.next()) { run query to get all active cases
var gdStart = new GlideDateTime(grcase.sys_created_on); giveRole function
reached.days event is fired
var nowTime = new GlideDateTime();
for each record the system process in a while loop, get
var date_diff = GlideDateTime.subtract(gdStart, nowTime);
create time store in start variable, get the current time
var nDays = parseInt(date_diff.getNumericValue()/86400000); and store it nowTime variable,
calculate the difference in numerical value divide by
// if diff is 90 days 86400000 to get the number of days
if (nDays == 90) {
catch(ex){
Event Registry
gs.info('Exception'+ex);
reached.days
}}
REQUIREMENT var rec = new GlideRecord('incident'); //replace
rec New GlideRecord(incident);
with actual name of table 1
Instance of GlideRecord New Keyword to create the instance
Using rec object and AddEncodeQuery , add query to get records created before 2021-11-03
AddEncodedQuery('sys_created_on<javascript:gs.dateGenerate('2021-11-03','00:00:00')');
gs is an object of GlideSystem and its method dateGenerate turn the input into date so it is
comparable to the sys_created_on field value
rec.query();
3
rec query();
41
now run a query for the result
4
while (rec.next())
{ result
0 1 ..
user rec object with next () method to load the next record for processing, this
Test the script in background to see the result. while is done for each existing record retuned by the query
5
rec.deleteRecord();
role New
1 GlideRecord(sys_group_has_role);
42
Use role object to dot walk group field, sys_id of the group is the value that is assign
Use role object to dot walk role field, sys_id of admin role is the value that is assign
role.inherits = true;
Test the script in background and check the appropriate group 5 role.inherits true
A user who gets this role will also be part of this group
role.insert();
6
role insert();
[{"lable":"value1"},{"label":"value2"},{"label":"value3"},{"label":"value4"},{"label":"value5"}..
2 parser JSON parse(str)
Turn the string into javascript object with parse method and store the result into the parser variable
43
for(var i=0;i<parser.length;i++){
For loop
arr.push(val.toString()); 5
}
arr push( val toString() );
Pushing val values into the array variable for each iteration in the for loop
gs.info('my values->' + arr.toString());
REQUIREMENT
System is
loading g_scratchpad
and Display Business Rule
rendering
44
the form
A Display Business Rule can instantiate g_scratchpad
object which can be passed to the client side and it
can be used in client script.
ServiceNow
rendered form
In order to change the value in the channel field based on the current logged in user, make use of a script include to check the user
group and a Display Business Rule to update specific value in the channel field.
Database
type: 'GlideUser' After the query, return grmember.hasNext(); it this statement is true
}; there is a record with the above condition /filter - false, there is no
such record.
Display Business Rule and Script Include True return, will execute the Business rule
Display Business Rule has two things, the first one is the script which update the channel to Helpdesk, the second one, it is
the condition field which contains the script include and the method. the script will check if the current user is part of group
listed in the system property, if yes the condition will then be true, which allows the br to update the field. prior to create the
br, define the system property with some groups in it.
REQUIREMENT
Make a ui action button make visible to just name ui_test application global
active
condition gs.getUser().isMemberOf(current.assignment_group);
45
Use a script in the condition field of the ui action, to check the members group and make it visible according to the
result
REQUIREMENT
46
when the system renders function onLoad() {
first the form and before
var user = g_user.hasRoleExactly('incident_impact_urgency_write');
the access is given to the
user in order to work with
the form,
2 With isNewRecord method (part of g_form
if (g_form.isNewRecord()) {
class) check if the form is loading
Simple client to get the caller id and alert it, this is onload client script
1
Take all values from a certain field on
create an empty array
47
while(auto.next()){
}
While loop, each time the record is processed
from the table u_alert_auto_close
gs.print(subjectsArray);
get the value with getValue method(part GlideRecord
Class)
and with the auto object, store the value in the subject
variable
48
Write a script to parse json string
REQUIREMENT
which will add values of two current refers to record object, retrieve description values like this current.description, same
logics for other fields.
different fields from the same table. store the concatenate value in a new field, and return it.
Example short description and var values = current.description + ' ' + current.short_description;
return values; // return the calculated value
description in one field
table incident application global
49
column label Add Two Field Values
calculated value
calculated
(function calculatedFieldValue(current) {
})(current);
REQUIREMENT
Concatenate the values of the 2 fields Add a string field, make it as function field
use the following code :
column label Add Two Field Values Function Field function field
50
function
glidefunction:concat(description, , ,short_description)