- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 09:58 AM
Hello Community.
I am stuck at piece of development. On my onChange Client Script below; I am trying to vet and see if the user is Authenticated to close a Release Task, and confrim if the user wants to Close Complete(State = 3 for close complete, and onChange is tied to the State field) a release task.
The client script works as intended for majority of Release Tasks closures, however for a handful of Release Tasks this script is executing twice, meaning the confirm pop-up is showing up twice.
I am not sure why this is the case. Does anyone have any ideas on simple remediation?
Much Thanks.
-Dominic
Solved! Go to Solution.
- Labels:
-
Enterprise Release Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 11:54 AM
Hey Dominic,
It's because your oldValue never gets changed to your newValue after the first confirm popup appears. Where are you setting oldValue and newValue? Since you're using oldValue for another function I would create a new variable outside of the onChange function and call it "oldState" which gets the initial state of the task (or you can set the value in the onLoad function). Then in the onChange function update the variable once it's inside your confirm code.
Something like this:
var oldState = g_form.getValue('state');
function onChange() {
var newState = g_form.getValue('state');
//other code
if (newState == 3 && aUC >1 && oldState != newState)
oldState = newState;
// confirm code
}
//other code
}
Let me know if this helps.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 11:14 AM
Hi,
In the Onchange client script you need to have this code at the front :
if (isLoading || newValue === '') {
return;
}
This will stop the script from running onLoad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 11:27 AM
Thanks for your response Mani.
That portion of the script is a part of the Client Script. I missed snipping that first portion of the code.
-Dominic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 11:17 AM
Hey Dominic,
Do you have any other business rules or client scripts making changes to fields on this form? There could be some other field that is changing when you try to change the state. Any other change on the field would retrigger the script and cause the confirm popup to appear again. Since you are only checking to see if the state field was changed you can add a check for oldValue != newValue such that:
if (g_form.getValue('state') ==3 && aUC >1 && oldValue != newValue)
This will ensure it won't trigger again if the state is already 3. Let me know if that works and if this was helpful.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2017 11:38 AM
Hi John.
Thanks for your response. I do have a few buisness rules and client scripts making changes to the table at close complete.
Thanks for your insight on adding an additional condition to the if statement. However, even after adding oldValue != newValue to the if statement, it still re-excueting the client script and causing the pop-up again to show up again.
-Dominic