Skip to content

Commit 7d927da

Browse files
Merge branch 'ServiceNowDevProgram:main' into main
2 parents 85f0d71 + 921b373 commit 7d927da

File tree

30 files changed

+822
-0
lines changed

30 files changed

+822
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Count Assigned To Field
2+
3+
1. Write a Client Script name as getAssignedToCount
4+
2. Glide the Incident Table
5+
3. Use onChange Client Script
6+
4. Use the Field name as "assigned_to" field
7+
5. Glide the Script Include using "GlideAjax".
8+
6. Call the function "getCount" from Script Include
9+
7. Add the parameter for the newValue.
10+
8. Use the getXML for asynchronous response.
11+
9. Get the answer using the callback function
12+
10. Use the logic for the more than how many tickets that error needs to populate
13+
11. Use the addErrorMessage for marking the error message
14+
12. Use the setValue for the "assigned_to" field.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function onChange(control,oldValue,newValue,isLoading,isTemplate) {
2+
if(isLoading || newValue === '') {
3+
return;
4+
}
5+
6+
var ga = new GlideAjax('countAssignedUtil');
7+
ga.addParam('sysparm','getCount');
8+
ga.addParam('sysparm_assignedto', newValue);
9+
ga.getXML(callback);
10+
11+
function callback(response){
12+
var answer = response.responseXML.documentElement.getAttribute("answer");
13+
if(answer >=5){
14+
g_form.addErrorMessage("Please select another person to work on this Incident, selected user is already having 5 tickets in his/her Queue");
15+
g_form.setValue("assigned_to", "");
16+
}
17+
}
18+
}
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var CallerInfoHelper = Class.create();
2+
CallerInfoHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
getCallerInfo: function() {
5+
var callerSysId = this.getParameter('sysparm_caller');
6+
if (!callerSysId)
7+
return JSON.stringify({ email: '', mobile: '' });
8+
9+
var userGR = new GlideRecord('sys_user');
10+
if (!userGR.get(callerSysId))
11+
return JSON.stringify({ email: '', mobile: '' });
12+
13+
var userObj = {
14+
email: userGR.email.toString(),
15+
mobile: userGR.mobile_phone.toString()
16+
};
17+
18+
return JSON.stringify(userObj);
19+
},
20+
21+
type: 'CallerInfoHelper'
22+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Display Custom Email/Phone Field Based on Incident Channel Field and Populate those Field with Caller Information
2+
3+
Displays either the **Email** or **Phone** field on the **Incident** form based on the selected **Channel** value (Email or Phone) and populate the fields with the caller’s details.
4+
5+
### Use Case
6+
- When **Channel = Email**, the **Email** field becomes visible and is auto-populated with the caller’s email address
7+
- When **Channel = Phone**, the **Phone** field becomes visible and is auto-populated with the caller’s mobile number
8+
- Both details fetched from the caller’s record from **sys_user** table.
9+
- The custom Email and Phone fields may also serve as placeholder to update if details differ from the caller record
10+
11+
### Prerequisites
12+
- Create Two custom fields on Incident Table
13+
- **u_email** which captures store the caller’s email address
14+
- **u_phone** which capture caller’s mobile number
15+
- Create **Two UI Policies** which hides the u_email and u_phone field unless channel choice is phone or email
16+
- Create an onChange Client Script that calls a GlideAjax Script to fetch the caller’s contact details and populate the custom Email or Phone field on the Incident form
17+
- To further enhance usecase Regex used on Phone field. Refer (https://github.com/ServiceNowDevProgram/code-snippets/pull/2375)
18+
19+
---
20+
21+
### Incident Record when channel choice is other than Email or Phone
22+
23+
![Display_CustomField_Autopopulate_Caller_3](Display_CustomField_Autopopulate_Caller_3.png)
24+
25+
---
26+
27+
### Incident Record when Channel choice is email and populate Email Field by caller's Email
28+
29+
![Display_CustomField_Autopopulate_Caller_1](Display_CustomField_Autopopulate_Caller_1.png)
30+
31+
---
32+
33+
### Incident Record when channel choice is phone and populate Phone Field by caller's Phone Number
34+
35+
![Display_CustomField_Autopopulate_Caller_2](Display_CustomField_Autopopulate_Caller_2.png)
36+
37+
---
38+
39+
40+
41+
42+
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading || newValue === '') return;
3+
4+
var ga = new GlideAjax('CallerInfoHelper');
5+
ga.addParam('sysparm_name', 'getCallerInfo');
6+
ga.addParam('sysparm_caller', newValue);
7+
8+
ga.getXMLAnswer(function(answer) {
9+
// Confirm what you’re actually receiving
10+
console.log("GlideAjax raw answer:", answer);
11+
12+
if (!answer) return;
13+
14+
var info;
15+
try {
16+
info = JSON.parse(answer);
17+
} catch (e) {
18+
console.log("Error parsing JSON:", e);
19+
return;
20+
}
21+
22+
g_form.setValue('u_email', info.email || '');
23+
g_form.setValue('u_phone', info.mobile || '');
24+
25+
});
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The custom widget that enables you to select multiple incidents in the portal page.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//HTML code that displays the incidents to select multiple at once.
2+
<div class="panel panel-default m-t">
3+
<div class="panel-heading">
4+
<h3 class="m-b-md">Complaints</h3>
5+
6+
<div class="form-inline"
7+
style="display:flex; align-items:center; flex-wrap:wrap; gap:12px;">
8+
<!-- Search -->
9+
<div class="form-group" style="margin-left:auto;">
10+
<div class="input-group">
11+
<input type="text"
12+
class="form-control"
13+
placeholder="Search complaints..."
14+
ng-model="c.searchText"
15+
ng-keypress="$event.keyCode==13 && c.searchIncidents()"
16+
style="min-width:250px;">
17+
<span class="input-group-addon" ng-click="c.searchIncidents()">
18+
<i class="fa fa-search"></i>
19+
</span>
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
25+
<div class="panel-body">
26+
<!-- Selected Count Indicator -->
27+
<div class="text-right text-muted" ng-if="c.getSelectedCount() > 0" style="margin-bottom: 8px;">
28+
<span class="label label-info" style="font-size: 13px; padding: 6px 10px;">
29+
{{c.getSelectedCount()}} complaint<span ng-if="c.getSelectedCount() > 1">s</span> selected
30+
(across pages)
31+
</span>
32+
</div>
33+
34+
<table id="incidentsList"
35+
class="table table-hover table-striped table-bordered"
36+
role="table">
37+
<thead>
38+
<tr>
39+
<th>
40+
<input type="checkbox"
41+
ng-checked="c.isAllSelectedOnPage()"
42+
ng-click="c.toggleSelectAll($event)"
43+
title="Select all on this page" />
44+
</th>
45+
<th>
46+
<a href="javascript:void(0)" ng-click="sortType='batchno'; sortReverse=!sortReverse">
47+
Run Date
48+
<span ng-show="sortType=='number' && !sortReverse" class="fa fa-caret-down"></span>
49+
<span ng-show="sortType=='number' && sortReverse" class="fa fa-caret-up"></span>
50+
</a>
51+
</th>
52+
<th><a href="javascript:void(0)" ng-click="sortType='caseid'; sortReverse=!sortReverse">
53+
Case ID
54+
<span ng-show="sortType == 'caller_id' && !sortReverse" class="fa fa-caret-down"></span>
55+
<span ng-show="sortType == 'caller_id' && sortReverse" class="fa fa-caret-up"></span>
56+
</a></th>
57+
<th><a href="javascript:void(0)" ng-click="sortType = 'policyid'; sortReverse = !sortReverse">
58+
Policy ID
59+
<span ng-show="sortType == 'short_description' && !sortReverse" class="fa fa-caret-down"></span>
60+
<span ng-show="sortType == 'short_description' && sortReverse" class="fa fa-caret-up"></span>
61+
</a></th>
62+
63+
</tr>
64+
</thead>
65+
66+
<tbody>
67+
<tr ng-repeat="item in c.incidentsList | orderBy:sortType:sortReverse">
68+
<td>
69+
<input type="checkbox"
70+
ng-checked="c.isChecked(item.sys_id)"
71+
ng-click="c.toggleCheckbox(item.sys_id, $event)" />
72+
</td>
73+
<td><a href="{{item.url}}">{{item.batchno}}</a></td>
74+
<td>{{item.caseid}}</td>
75+
<td>{{item.policyid}}</td>
76+
</tr>
77+
<tr ng-if="!c.complaintsList.length">
78+
<td colspan="9" class="text-center text-muted">No incidents found.</td>
79+
</tr>
80+
</tbody>
81+
</table>
82+
83+
<!-- Pagination Controls -->
84+
<div class="pagination-controls text-center" style="margin-top:10px;">
85+
<button class="btn btn-default" ng-disabled="c.pageNumber===1" ng-click="c.prevPage()">Prev</button>
86+
<span> Page {{c.pageNumber}} of {{c.totalPages}} </span>
87+
<button class="btn btn-default" ng-disabled="c.pageNumber===c.totalPages" ng-click="c.nextPage()">Next</button>
88+
</div>
89+
</div>
90+
</div>

0 commit comments

Comments
 (0)