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

You shouldn't have to do this, but you can also try wrapping the code in an if statement. I have had to do that before. Also, these are onChange only, so it should only run if the value is changed. It won't run on form load (if you were expecting that).



if(newValue){


//do stuff


}


I've wrapped it in an IF statement, but still, it only works if it's a new record.   After submission, the Client Script stops responding when the Type, Subtype, or Category Choice is changed.


Have you defined whether it is not running your client script or whether it isn't getting a return value from your ajax call? What is your ajax call doing and why is it only represented in one of the scripts?



This doesn't seem to be as complex as these scripts make it out to be, you are only trying to set a value based on the value of 3 fields; however not being able to directly interact with the code makes the debugging a little harder. This is how I would see the functionality, please correct me if I am wrong.



If any change to Type, Subtype, or Category; call a custom table (u_type_subtype_category) to validate the correct Business / Technical Service value based on the associated values, or replace if incorrect.



Is it important to track it in real-time in the UI, or could the update be made based on an update to the form? If the latter, then you could use a business rule, so that you could utilize the condition of "current.u_type.changes() || current.u_subtype.changes() || current.u_category.changes()" and write one script to function based on all of these changes. This would also eliminate the need for the ajax call.


It is a pretty simple Client Script.   And, to answer your question about functionality, you have it correct.   Here are the exact stipulations:



1)   When Subtype changes, check to see if there are any options for Category.   If no, do not make Category mandatory and fill in the info for Business Service and Technical Service.


2)   When Subtype changes, check to see if there are any options for Category.   If yes, make Category mandatory and do nothing with Business Service or Technical Service yet.   Then, in another Client Script, wait for Category to change and then fill in the Business Service and Technical Service.



If at any point Type changes, it will change Subtype and Category to NONE.   When that happens, our first client Script(CM - Mandatory Incident Category) will set Business Service and Technical Service to empty.   When this happens, we're back to step 1 and waiting for Subtype to change in order to see if there is a Category or not.  



Again, everything works and alerts exactly what we're wanting until you submit the Incident.   After that, we get nothing except for Subtype and Category being set to NONE due to the fact that they're dependent on the former Choice Field.  



I wouldn't mind doing a Business Rule on this, but in the spec from the Help Desk, it is being requested to happen on the fly.   I've got an Incident in with HI to find out what is causing the Client Script to stop running after submission.   If this all fails and we can't find a solution, I will go the Business Rule route.   I made a change to the first Client Script.   I got rid of the GlideAjax all-together.   Here is a new screen shot of the code.   It's doing exactly the same thing, but it's actually running faster when it's a New Incident.



find_real_file.png


DUGGI
Giga Guru

Can i see the code?