- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 10:33 AM
Hello and happy Friday! I am looking for assistance on the script below. This should only run when a user modifies the Planned End Date field from one date to another. It should not run when the form is first loaded. However, the script is running when a user creates an new Project Task, and, when the user opens an existing Project Task.
I understand that the second line in the code should be preventing it from running when the form loads, but it doesn't.
Can anyone help me out with this?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (oldValue != '') { //Check if the Planned End Date field was blank
g_form.addErrorMessage('Planned End Date changed. Please complete the template in the Work Notes field and provide details as to why the Planned End Date was modified.');
var myFieldValue = g_form.getValue('work_notes'); //Put the value of the work_notes field into a variable.
//if (myFieldValue.toString().length < 1000) { // Verify number of characters currently in the Work Notes field.
g_form.setValue('work_notes', 'Planned End Date updated. Complete the following template and provide details as to why the Planned End Date was modified: \n\nCurrent Status: \nNext Steps: \nNew Planned End Date: \n\n\nExamples: \n\nCurrent Status: This documentation is being written. I have steps completed for how to update the system. \nNext Steps: I will need access to server wexap100 before I can obtain the final screenshots. I have reached out to the Microsoft team to request this access. \nNew Planned End Date: 2022-11-19 16:01:15 \n\nCurrent Status: The access has been provided. Please test the access \nNext Steps: We are moving the Planned End Date to allow time to test access to the system. \nNew Due Date:2022-11-15 16:01:15\n\n' + myFieldValue); //Populates the Customer Notes field with the text in the string. \n for a new line.
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 10:47 AM
You can give it a try by adding a and condition in the script as:
if (oldValue != '' && oldValue != newValue)
It indicates that when value gets changed, it will trigger
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 10:45 AM
Hi @Justin-DNV ,
I don't think this script is running onLoad. There might be some other script that is causing the issue.
Also do check on what field this onChange Script works because there might be a case where any one of the onLoad script is changing one of the field values and it might be triggering this onChange script.
Mark helpful if it helps in Solving your query.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 10:47 AM
You can give it a try by adding a and condition in the script as:
if (oldValue != '' && oldValue != newValue)
It indicates that when value gets changed, it will trigger
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 11:25 AM
Simply change isLoading == 'false'
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading == 'false' || newValue === '') {
alert ('hello')
return;
}
if (oldValue != '' && oldValue != newValue) { //Check if the Planned End Date field was blank
g_form.addErrorMessage('Planned End Date changed. Please complete the template in the Work Notes field and provide details as to why the Planned End Date was modified.');
var myFieldValue = g_form.getValue('work_notes'); //Put the value of the work_notes field into a variable.
//if (myFieldValue.toString().length < 1000) { // Verify number of characters currently in the Work Notes field.
g_form.setValue('work_notes', 'Planned End Date updated. Complete the following template and provide details as to why the Planned End Date was modified: \n\nCurrent Status: \nNext Steps: \nNew Planned End Date: \n\n\nExamples: \n\nCurrent Status: This documentation is being written. I have steps completed for how to update the system. \nNext Steps: I will need access to server wexap100 before I can obtain the final screenshots. I have reached out to the Microsoft team to request this access. \nNew Planned End Date: 2022-11-19 16:01:15 \n\nCurrent Status: The access has been provided. Please test the access \nNext Steps: We are moving the Planned End Date to allow time to test access to the system. \nNew Due Date:2022-11-15 16:01:15\n\n' + myFieldValue); //Populates the Customer Notes field with the text in the string. \n for a new line.
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 11:25 AM
Have you tried changing this line
if (isLoading || newValue === '') {
To
if (isLoading) {
Also have you put in an alert or console.log like to see when its triggering to make sure its doing it when you think it is?