After submitting Incident, Client Script stops working

cwmurphy
Mega Expert

Hello,

        I have a couple onChange Client Scripts that set two reference values based on other choices on the Incident form.   When a new Incident form is loaded, making changes to the Type, Subtype, and Category boxes will auto-populate our Business Service and Technical Service reference fields.  

Here is a screen shot of the top half of our Incident form when creating new:

find_real_file.png

As you see here, I have made changes to the Type, Subtype, Category fields and the Business/Technical Service was filled in by our Client Script:

find_real_file.png

If I change any of the values already selected on the left side of the form, the right side is set to blank and waits for proper values.   As long as this is a new record, this Client Script works without issue.   However, once saved, it stops working.   I can change the left side of the form, but nothing on the right changes as it's supposed to:

find_real_file.png

The Business Service for the above example should have been changed to: Shared Services - IT Software

The Technical Service for the above example should have been changed to: DB Hosting - Oracle

Is there something that I'm missing to have a Client Script work after a form is no longer a New Record?

1 ACCEPTED SOLUTION

cwmurphy
Mega Expert

After many hours looking into this and trying to find the reason it wasn't working, a solution has been found!   An onLoad script that set the cursor focus for the Incident Table was throwing an error when "isNewRecord" returned false.   It appears a field we put on the Incident Table a few months ago was removed.   That onLoad script was supposed to select that field.   It's now set to focus on Short Description and all of the above onLoad/onChange code works just fine.



Thank you to everyone that put in the time to debug with me.   This is the reason I enjoy being a part of this community.


View solution in original post

15 REPLIES 15

mike_allgire
Giga Guru

Client Scripts should work in any context as long as the fields are available on the form and the conditions match. With what you are doing, would it make more sense to use Data Lookup and Record Matching Support - ServiceNow Wiki instead of a client script to map the values based on the selections?


I have an onChange Client Script that shows me all of my alerts when the Incident is a new record.   When it's been saved, I get no more alerts.   This onChange is looking specifically at the Subtype field.  



Also, I have read through the link you posted.   It is an option.   With that, I have questions.   How would it affect the Business Service and Technical Service fields on Incidents that have already been submitted?   These two fields have been in use since our implementation last year.   The Type, Subtype, and Category fields are just now being developed, so there is no live data out there.   Also, there are times where we have a Type and a Subtype, but they don't relate to a Category. Does the Data Lookup and Record Matching account for something like that?


find_real_file.png


Based on your comments, the Data Lookup may not be the best option do to the historical, because it would change those values if the type, subtype and category fields were changed.


Thanks for the info.   I'm not sure why even simple Client Scripts aren't working after an Incident has been submitted.   I've opened a HI ticket for more assistance.