How to manage state flow using the state options on incident form

sony8
Tera Contributor

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

 

 

1 ACCEPTED SOLUTION

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

https://instance/sys_script_client.do?sys_id=7ebdc3c15357101034d1ddeeff7b12e3&sysparm_record_target=...

 

https://instance/sys_script.do?sys_id=0aa20f7ec39132001488b731c1d3ae9e&sysparm_record_target=sys_scr...

Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

8 REPLIES 8

Please mark my response as correct and close the thread.

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hello,

Looks like you have marked your own response as correct although I gave you idea about solution.

Please hit like and mark my response as correct if that helps
Regards,
Musab

@Musab Rasheed  sorry for that..i marked helpful and mistakenly did that .. now I have corrected.

 

Thank you so much for your support 😊

Community Alums
Not applicable

Hi, isNewRecord() method is applicable only for a new form means unsaved form. After saving, script won't work if you use isNewRecord()

 

As per your script, when state is set to In progress, resolved dropdown also will come up.

I would suggest you to use the onload script and show the states respectively. So in this case unless the state is set to In progress, users won't see resolved option.

 

Please mark my response as helpful/correct if this helps