Task1:
Restrict form submission if description and assignment group is empty.
BEFORE INSERT:
(function executeRule(current, previous /*null when async*/ ) {
if (current.description.nil() && current.assignment_group.nil()) {
current.setAbortAction(true);
})(current, previous);
========================================================================
======
Task2:
Populate assignment group with Service desk and assigned to as ITIL user
BEFORE INSERT:
(function executeRule(current, previous /*null when async*/ ) {
current.assignment_group = "d625dccec0a8016700a222a0f7900d06";
current.assigned_to = "681b365ec0a80164000fb0b05854a0cd";
})(current, previous);
========================================================================
======
Task3:
Change contact type to phone if category is software (update)
BEFORE UPDATE:
(function executeRule(current, previous /*null when async*/ ) {
current.addQuery('category', 'software');
current.query();
current.contact_type = "phone";
current.update();
})(current, previous)
========================================================================
======
Task4: if the user is having Admin role show only priority 1,ctageory-harware,state - new tickets.
BEFORE QUERY:
(function executeRule(current, previous /*null when async*/ ) {
if (gs.hasRole('admin')) {
current.addQuery('priority', '1');
current.addQuery('category', 'hardware');
current.addQuery('state', '1');
})(current, previous);
gs.userID() UI When to run --> Role admin.
========================================================================
======
Task5:
Show caller email id, company, mobile number and manager when form loads.
DISPLAY:BR
(function executeRule(current, previous /*null when async*/ ) {
g_scratchpad.caller = current.caller_id.email.getDisplayValue();
g_scratchpad.company = current.caller_id.company.getDisplayValue();
g_scratchpad.manager = current.caller_id.manager.getDisplayValue();
g_scratchpad.mobilephone = current.caller_id.mobile_phone.getDisplayValue();
})(current, previous);
CLIENT SCRIPT:
function onLoad() { // inc is an Array
var inc =
[g_scratchpad.caller,g_scratchpad.company,g_scratchpad.manager,g_scratchpad.mobilephone]
alert(inc);
}
gs.addInfoMessage('Caller email '+ current.caller_id.email);
gs.addInfoMessage('Caller company '+ current.caller_id.company.name);
gs.addInfoMessage('Caller mobile '+ current.caller_id.mobile);
gs.addInfoMessage('Caller manager '+ current.caller_id.manager.name);
========================================================================
======
Task6:
BEFORE INSERT
(function executeRule(current, previous /*null when async*/ ) {
var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT', 'caller_id');
agg.addQuery('caller_id', current.caller_id); //present caller on incident form
agg.query();
while (agg.next()) {
//do things on the results
var incidentCount = agg.getAggregate('COUNT', 'caller_id');
gs.addInfoMessage("Total count for caller->" + incidentCount);
})(current, previous);
========================================================================
======
Task 7:
INCIDENT
AFTER INSERT:
Create a problem Record when incident ticket is created.
(function executeRule(current, previous /*null when async*/ ) {
var prb = new GlideRecord('problem');
prb.initialize();
prb.first_reported_by_task = current.sys_id;
prb.insert();
var newprb = prb.insert();
current.problem_id = newprb;
current.update();
})(current, previous);
Task 8:
Attach a child incident to any incident, when the parent incident short description
Is changed the child incident short description should also updated.
AFTER INSERT:
(function executeRule(current, previous /*null when async*/ ) {
Var inc = new GlideRecord(‘incident’);
Inc.addQuery(‘parent_incident’, current.sys_id); // parent incident with sys_id’s of incidents
// just like how we query
Prob.addQuery(‘problem_id’,current.sys_id);
Inc.query();
While (inc.next()) {
Inc.short_description = current.short_description;
Inc.update();
})(current, previous);
Task 9:
Update the associated change request assignment group with the problem record assignment
Group from the problem record.
AFTER UPDATE:
(function executeRule(current, previous /*null when async*/ ) {
Var chng = new GlideRecord(“change_request”);
Chng.addQuery(“rfc”, current.sys_id); // querying the related problem record and
Change_request record
Chng.query();
While (chng.next()) {
Chng.short_description = current.short_description;
Chng.update();
})(current, previous);
========================================================================
======
Task 10:
Close the related incident ticket from problem form.
AFTER UPDATE:
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
inc.addQuery('problem_id',current.sys_id);
inc.query();
while(inc.next()){
inc.state = "7";
inc.close_code = "Solved(Permanently)";
inc.close_notes = "Closed coz problem is Closed";
inc.update();
})(current, previous);
========================================================================
======
Task 11:
Create change task on change record , when change record is closed the related change task
should also close // and send notification to requested by.
AFTER INSERT
AFTER UPDATE
(function executeRule(current, previous /*null when async*/ ) {
var chng = new GlideRecord('change_task');
chng.addQuery('change_request', current.sys_id);
chng.query();
while (chng.next()) {
chng.state = current.state;
chng.update();
})(current, previous);
========================================================================
======
Task 12:
Create a table called "Info" with a field called "Description".
Create another table called "BackUpInfo" with a field called "Description”.
Create a business rule on "Info" such that whenever the records are inserted or updated in it, it
is also reflected in "BackUpInfo" table.
AFTER INSERT:
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord("u_backup");
gr.initialize();
gr.u_refinfo = current.sys_id;
gr.u_backup_description = current.u_description;
gr.insert();
})(current, previous);
AFTER UPDATE:
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord("u_backup");
gr.addQuery("u_refinfo", current.sys_id);
gr.query();
if (gr.next()) {
gr.u_backup_description = current.u_description;
gr.update();
})(current, previous);
========================================================================
======
Task 13:
Write a business rule on any table to create a scratch pad variable.
Use that scratch pad in the onload script and perform some manipulation like hiding some fields.
DISPLAY: TABLE NAME IS JADE
(function executeRule(current, previous /*null when async*/) {
G_scratchpad.caller = current.caller_id.getDisplayValue();
})(current, previous);