Onchange client script triggerd on Load

Tomer
Kilo Expert

Hello experts,

i'm trying reach this functionality: when supporter turns ticket to resolve/pending, assign it to him automatically by Onchange client script. 

We need this as a client script and not BR cause we want the supporter will see this change immediately. 

Here is my piece of code:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue=="Resolved" || newValue=="Pending"){
var supporter = g_user.userID.toString();
g_form.setValue('assigned_to',supporter);
}

This is working, but makes a weird bug - works on load and changes the assignee (without saving) when he is just looking at the ticket - when the status field not change

Thank you for any kind of help,

Tomer.

find_real_file.png

5 REPLIES 5

Allen Andreas
Administrator
Administrator

Hi,

You may need to check and see if you have a separate onLoad client script or UI policy? as well....per this, it would only take effect if the newValue is Resolved or Pending. So either something is running onLoad...changing the value of the Status (u_corporate_status) field...or you have something else running as well.

The beginning line with:

if (isLoading || newValue === '') {

return;

}

Is stopping this from taking effect when the form loads or when the new value is null...so this wouldn't be running onLoad.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

ggg
Giga Guru

if (newValue=='7'){ //enter the database values for the state
      
        g_form.setValue('assigned_to', g_user.userID);


        alert('1');
    }
    else {
        alert('2');
    }

vkachineni
Kilo Sage
Kilo Sage

put a console.log() message after line 5 to see if the onchange is getting triggered onLoad. Also try to log the newValue that is sent in.

If this is not executing onLoad, then there might be some other UI policy making the changes onLoad.

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Tomer
Kilo Expert

Thank you everyone!