Skip to content

Commit 6579f1b

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents dd6ade3 + 93891d6 commit 6579f1b

File tree

47 files changed

+1814
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1814
-10
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+
}
Loading
Loading

0 commit comments

Comments
 (0)