}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2018 10:39 AM
Hello, when we create an incident from a connect support chat session the chat session caller's name will load on the incident form, we have a client script below that sets the caller's business phone on the incident form so support doesn't have to type in the callers phone number every time. The script works fine for this but when we open an incident from Create New since a caller does not load the script sets the business phone field as undefined (see attached). Would like the business phone field to not display "undefined" if a caller does not load, can anyone help with this? Thanks
function onLoad() {
var caller = g_form.getReference('caller_id', loadLocation);
}
function loadLocation(caller) {
if (caller){
g_form.setValue('location', caller.location);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2018 06:34 PM
Guys,
This solution works but I wanted to point out that this code isn't formatted the best and can be VERY inefficent. Nesting if statements makes the code harder to debug and is not as maintainable moving forward. I wanted to take a moment to point out Short-Circuit or minimal evaluation...
Basically, in C based languages (like Javascript) you can write a single line conditional statement such as:
if(caller && caller.phone){
//if both conditions are true, this code executes
}
Why is this better and what constitutes a short circuit? If the first value evaluates to false, the second value will NEVER be evaluated. This can dramatically speed up code execution! For example, if I want to check if a local variable is true BEFORE I evaluate a long running function (like a full round trip back to the database), I just have to put things in the right order:
if(localVar && GetFromDatabase()){
//The round trip to the database will only happen if localVar evaluates to true!
}
This will especially be useful in your OnLoad client script if you have any blocking calls. Don't make the user wait for the page to load if it isn't necessary!!
In the example that you gave, both variables will need to be evaluated every...single...time the code is executed.
/endrant

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2018 10:55 AM
Hi,
As far as I understood, I could figure this out.
function onLoad() {
var caller = g_form.getReference('caller_id', loadLocation);
function loadLocation(caller) {
if (caller){
g_form.setValue('business_phone',caller.phone);//if you want to set business_phone as empty, replace caller.phone with ''
g_form.setValue('location', caller.location);
}
}}
Correct me if I misunderstood the question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2018 11:04 AM
Hi,
So when you open a new incident from create new the client script runs and the business field says undefined.
Here you can add a condition to run the client script if the incident record is new or not.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2018 12:22 PM
Sorry i put in the wrong code, it is this below.
function onLoad() {
var caller = g_form.getReference('caller_id', loadPhone);
}
function loadPhone(caller) {
if (caller){
g_form.setValue('u_business_phone', caller.phone);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2018 12:24 PM
Abhishek i tried adding your script but it did not work, not sure it would anyway because when we create ticket from a chat session that is also i believe considered new.
Archana, what you suggested works when creating incident from Create New but i want the business phone to load when we open a incident from the chat session so this is not going to work either.