- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 07:55 AM - edited 07-17-2023 07:56 AM
Dear Team,
I have a requirement-
In the incident table, I want the caller (caller_id) to populate as Impacted User (u_impacted_user) when the Impacted User field is blank.
Then location (u_location) field should populate with the Impacted User's location.
I wrote 2 OnChange Client Scripts as shown below:
1st-
Name:setImpactedUser as of caller
Table: Incident
Type:onChange
Field name: Caller
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var callerUsr = g_form.getReference('caller_id');
g_form.setValue('u_impacted_user',callerUsr.name);
}
2nd-
Name:setLocation of Impacted User
Table: Incident
Type:onChange
Field name: Impacted User
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var impactedUsr = g_form.getReference('u_impacted_user');
g_form.setValue('u_location',impactedUsr.location);
}
But this is not working as desired because I am not good at applying conditions like here what we want is that- If any INC record(s) have the Impacted User (u_impacted_user) field Blank then only the Impacted User field should get auto-populate with the name as same of Caller (caller_id). Further, it should auto-populate the Location (u_location) field with the Impacted User's location.
Thanks in advance, please help to achieve this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 09:41 AM
Modify the on load script like below
function onLoad() {
if (g_form.getValue('u_impacted_user') == '') {
var impactuser = g_form.getReference("caller_id", loadImpactUser);
function loadImpactUser(impactuser) {
g_form.setValue("u_impacted_user", impactuser.sys_id);
g_form.setValue("location", impactuser.location.sys_id);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 09:41 AM
Modify the on load script like below
function onLoad() {
if (g_form.getValue('u_impacted_user') == '') {
var impactuser = g_form.getReference("caller_id", loadImpactUser);
function loadImpactUser(impactuser) {
g_form.setValue("u_impacted_user", impactuser.sys_id);
g_form.setValue("location", impactuser.location.sys_id);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 09:52 AM
@Manmohan K This is working as expected but not sure why this '!' mark is coming at this li
function loadImpactUser(impactuser) {
Move function declaration to function body root', can we remove this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 09:55 AM
Modify code like below to remove the ! prompt
function onLoad() {
if (g_form.getValue('u_impacted_user') == '') {
var impactuser = g_form.getReference("caller_id", loadImpactUser);
}
function loadImpactUser(impactuser) {
g_form.setValue("u_impacted_user", impactuser.sys_id);
g_form.setValue("location", impactuser.location.sys_id);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 09:46 AM