Client Script Issues running twice in SOW

johndoh
Mega Sage

Can anyone help me understand why this simple script is causing the info message to be displayed twice only within SOW?

 

johndoh_1-1743464837664.pngjohndoh_2-1743464868874.png

johndoh_0-1743465042362.png

 

I should add there is no other onChange client scripts that are associated with this field. Checking or unchecking isolated script appears to make no difference once so ever.

1 ACCEPTED SOLUTION

johndoh
Mega Sage

From our SOW admin:

 

I went and duplicated the new record page and checked the whole duplication issue after and everything seems to be working just fine now.

View solution in original post

13 REPLIES 13

@johndoh 

Hmm that's the only thing which might cause this.

I used script from @Vishal Jaswal and it worked fine as well in SOW

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

works fine in my PDI as well and what has me wanting to pull my hair out.

This makes zero sense but for this script this seems to work:

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || isTemplate) {
        return;
    }
    
    // Define the field name explicitly
    var fieldName = 'description'; // Replace 'your_field_name' with the actual field name

    // Add a delay of 5 seconds before executing further actions
    setTimeout(function() {
        // Check if the field is still populated
        if (g_form.getValue(fieldName)) {
            return;
        }
        
        if (newValue === 'email') {
            console.log('Testing');
            g_form.addInfoMessage('Testing');
            g_form.setValue('description', 'test');
        } else {
            g_form.clearMessages();
        }
    }, 5000); // 5000 milliseconds = 5 seconds
}

 

 

I have tried to update my script following this format but not successful thus far but leads me further into there is a loop or something causing it to run twice.

@johndoh 

any other client script is setting channel and causing the script to trigger and hence show the message?

I don't think domain separation should have any say in this

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Why I created this script on the Channel field and not the State field as I thought that might be the issue. There is no other client script on this field that I can find. Seems to be any client script running twice within SOW only.

@johndoh 

Something is causing this definitely.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader