- 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 08:25 AM
Thanks @Rahul Talreja for your response, but I think it is not working as expected because it is not auto-populating fields per below desired scenario-
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 the same Caller (caller_id). Further, it should auto-populate the Location (u_location) field with the Impacted User's location.
I think it should be achieved through the onLoad Client Script to check for the current record if the Impacted user field is empty so populate this field with the same name as of Caller and further populate the Location field as of the location of the Impacted user that was just already auto-populated.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 08:47 AM
Hi @Rahul Talreja thanks for your efforts, it is not working as desired and explained above, when I open any such record (which has an Impacted user blank), then that record's Impacted User field is not getting auto-populated with the same as the caller's name.
Further, it should populate the Location field with location of recently auto populated Impacted User
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 09:04 AM
Hi @rishabh31
Create a on load client script as below and let me know if it populates the impacted user
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 09:38 AM
Hey @Manmohan K , That is working as expected. Thanks
One more thing left i.e., Location part