- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2021 11:41 AM
Hello all,
We have an onChange client script setup - whenever a caller is filled in, the location will be auto-populated on the incident form. But when the impacted user (not mandatory field) is filled in, it overrides the location of the caller and replaces the value with the impacted user's location. However, for eg, if tech by mistake uses the impacted user field and has a location for 'impacted user' on the incident form and then decides just to go with the caller field, the caller's location does not auto-populate and leaves the location as 'blank'. Is there any way to re-populate the value of the caller's field after the impacted user is used and then left blank? I am also pasting the scripts for reference. Any lead would be appreciated.
(BP) Set Location to User :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
if (newValue == '' || newValue == null) {
g_form.setValue('u_location', '');
return;
}
if (!g_form.hasField('u_location'))
return;
var caller = g_form.getReference('u_impacted_user', setLocation);
function setLocation(caller) {
if (caller)
g_form.setValue('u_location', caller.location);
}
}
Impacted User Location :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.setValue('u_location', '');
return;
}
if (!g_form.getControl('u_location')) {
return;
}
var caller = g_form.getReference('u_impacted_user', setContactNumber);
}
function setContactNumber(caller) {
if (caller) {
g_form.setValue('u_location', caller.location);
}
}
If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2021 12:45 PM
You can implement via onChange client script. Write below code in impacted user change client script
if (newValue == '') {
var caller = g_form.getReference('caller_id', setContactNumber);
return;
}
if (!g_form.getControl('u_location')) {
return;
}
var caller = g_form.getReference('u_impacted_user', setContactNumber);
function setContactNumber(caller) {
if (caller) {
g_form.setValue('u_location', caller.location);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2021 12:02 PM
Use below script on impacted user onChange client script.
if (newValue == '') {
var caller = g_form.getReference('caller_id', setContactNumber);
return;
}
if (!g_form.getControl('u_location')) {
return;
}
var caller = g_form.getReference('u_impacted_user', setContactNumber);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2021 12:18 PM
Hi Saloni,
To achieve this you can use similar code in both the scripts only change will be
var caller = g_form.getReference('opened_by', setLocation); //replace the field with your fieldname
var caller = g_form.getReference('caller_id', setLocation);
In my case it would be like this...
FOR ONCHANGE OF CALLER FIELD
-------------------------------------------------------------
function onChange(control, oldValue, newValue, isLoading) {
if ((isLoading && !g_form.isNewRecord()) || (g_form.isLiveUpdating && g_form.isLiveUpdating()))
return;
if (newValue == '' || newValue == null) {
g_form.setValue('location', '');
return;
}
if (!g_form.hasField('location'))
return;
var caller = g_form.getReference('caller_id', setLocation);
}
function setLocation(caller) {
if (caller)
g_form.setValue('location', caller.location);
}
-----------------------------------------------------------------
FOR ONCHANGE OF OPENED BY FIELD
-----------------------------------------------------------------
function onChange(control, oldValue, newValue, isLoading) {
if ((isLoading && !g_form.isNewRecord()) || (g_form.isLiveUpdating && g_form.isLiveUpdating()))
return;
if (newValue == '' || newValue == null) {
g_form.setValue('location', '');
return;
}
if (!g_form.hasField('location'))
return;
var caller = g_form.getReference('opened_by', setLocation);
}
function setLocation(caller) {
if (caller)
g_form.setValue('location', caller.location);
}
Please try and let me know if you face any issues.
Thanks
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2021 12:37 PM
Hi Johnny,
Thank you for the script!! It still does the same thing!! When the caller field is used, the location auto-populates as well as the same with the impacted user. But when I clear the impacted user, it does not revert back to the caller's location and keep the location empty.
If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2021 12:45 PM
You can implement via onChange client script. Write below code in impacted user change client script
if (newValue == '') {
var caller = g_form.getReference('caller_id', setContactNumber);
return;
}
if (!g_form.getControl('u_location')) {
return;
}
var caller = g_form.getReference('u_impacted_user', setContactNumber);
function setContactNumber(caller) {
if (caller) {
g_form.setValue('u_location', caller.location);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2021 01:00 PM
Hi Saloni, Misunderstood the requirement, you can achieve it like this.
Refer the code under //---------
function onChange(control, oldValue, newValue, isLoading) {
if ((isLoading && !g_form.isNewRecord()) || (g_form.isLiveUpdating && g_form.isLiveUpdating()))
return;
//--------------------------------------------------------------
var caller;
if (newValue == '' && g_form.getValue('opened_by') != '') {
caller = g_form.getReference('opened_by', setLocation);
return;
}
//--------------------------------------------------------------
if (!g_form.hasField('location'))
return;
caller = g_form.getReference('caller_id', setLocation);
}
function setLocation(caller) {
if (caller)
g_form.setValue('location', caller.location);
}
Similarly do for other script as well.
Please mark helpful/correct if it worked.
Thanks
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
