How to set resolution code to 'User error' using Client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 12:10 AM
Hello,
I am trying to set the resolution code to 'user error' upon setting the state to 'Resolved' and Assigned to 'Fred Luddy' but my code seems not to be working at all.
Thank you for the help.
function onSubmit() {
//Type appropriate comment here, and begin script below
var Stat = g_form.getValue('state');
var Assignedp = g_form.getValue('assigned_to');
var res = g_form.getValue('close_code');
var resn = g_form.getValue('close_note');
if( Stat == '6' && Assignedp == '5137153cc611227c000bbd1bd8cd2005')
{
g_form.setValue('close_code','User error');
g_form.setValue('close_note', 'cant be resolved');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 09:51 AM - edited 11-05-2023 09:52 AM
Here's an example of how to use an onChange script for the 'state' field:
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading) {
var assignedTo = g_form.getValue('assigned_to');
if (newValue === '6' && assignedTo === '5137153cc611227c000bbd1bd8cd2005') {
g_form.setValue('close_code', 'User error');
g_form.setValue('close_note', "Can't be resolved");
}
}
}
In this script:
- onChange is called whenever the 'state' field changes.
- It checks if the new state is '6' (Resolved) and if the assigned_to field is '5137153cc611227c000bbd1bd8cd2005' (Fred Luddy).
- If both conditions are met, it sets the 'close_code' and 'close_note' fields accordingly.
Please make sure the sys_id values and state codes are correct, and that this script is associated with the 'state' field's onChange event.
Mark as accepted solution & helpful if it suffices your requirement

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 11:07 AM
@Timothy Oyetade I have tested with the following script and it ran fine for me.
function onSubmit() {
var Stat = g_form.getValue('state');
var Assignedp = g_form.getValue('assigned_to');
var res = g_form.getValue('close_code');
var resn = g_form.getValue('close_note');
if (Stat == '6' && Assignedp == '5137153cc611227c000bbd1bd8cd2005') {
g_form.setValue('close_code', 'User error');
g_form.setValue('close_notes', 'cant be resolved'); //You used incorrect field name close_note whereas it is close_notes
}
}
Also, there are some OOTB Client script and Data policy available which won't let this OnSubmit trigger, unless they are marked in active. Following are the names of them.
1. Client Script: (BP) Close Mandatory on Close or Resolve
2. Data Policy: Make close info mandatory when resolved or closed
Hope this helps.