- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:32 AM - edited 11-23-2022 05:33 AM
I have below requirement.
the state drop down values need to be managed based on each value.
drop down values are: New , In progress, Resolved and Closed
for the above values i have written below onchange of state script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var IncState = g_form.getValue('state');
if (IncState == '1') {
g_form.addOption('state', '1', 'New');
g_form.addOption('state', '2', 'In progress');
g_form.removeOption('state', '4', 'Resolved');
g_form.removeOption('state', '5', 'Closed');
} else if (IncState == '2') {
g_form.addOption('state', '1', 'New');
g_form.addOption('state', '2', 'In progress');
g_form.addOption('state', '4', 'Resolved');
g_form.removeOption('state', '5', 'Closed');
} else {
g_form.addOption('state', '1', 'New');
g_form.addOption('state', '2', 'In progress');
g_form.addOption('state', '4', 'Resolved');
g_form.addOption('state', '5', 'Closed');
}
}
Here I am facing issue with onchange of state values.
when i change the state from new to In Progress without saving form, the value selected in state is in progress the values showing was New , In progress, Resolved ... Now without saving the form the user clicked on Resolved and was able to move to closed state..
Anyone having idea regarding isNewRecord method on onchange script..
expected output :
state: New --------option1 -New , option2 -In Progress
state: Inprogress -------- option1 -New , option2 -In Progress, option3 -Resolved
state: others(i.e. Resolved or Closed ) --- option1 -New , option2 -In Progress, option3 -Resolved, option4 - Closed
Please help me for checking old and New records for the same.
Thank you in Advance
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 06:07 AM
I suggest you write onload client script instead of onchange client script, Change has onload logic and not on change logic, with this you will eliminate all these issues, You can refer below scripts from change but you may find it difficult to understand but I suggest you implement this on onload
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:38 AM - edited 11-23-2022 05:40 AM
Hello,
If you want your code to run only for new Record then use g_form.isNewRecord() function before your on change script starts.
Sample :
if(g_form.isNewRecord())
{
on change script
}
Also, check Change form, you can see similar logic over there
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 05:55 AM
@Musab Rasheed can you please share the code for the same .. since my onchange was working but when we edit the state value it was behaving different for state = In progress we can select resolved option then user again check the state drop down getting closed option before saving form. In this case how to use that NewRecord method in my script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 06:07 AM
I suggest you write onload client script instead of onchange client script, Change has onload logic and not on change logic, with this you will eliminate all these issues, You can refer below scripts from change but you may find it difficult to understand but I suggest you implement this on onload
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 06:47 AM
@Musab Rasheed working fine i have deactivated onchange and written it onload script same code.
Thank you so much