SetValue is not working in AgentWorkspace and serviceoperation workspace

Saranya K
Tera Contributor

Hi all

 

We written a onchange client script so, whenever the assignment group change then the state should set to 'New'

in our instance 'New' choice will not be available in form once the incident is moved to  'In progress'.

 

I have written below on change client script  when assignment group change

 

SaranyaK_0-1706011652904.png

 

it's working fine in normal UI

 but in Agentworkspace and Serviceoperation the state filed is setting to empty instead of "new"

 

Thanks

 

 

4 REPLIES 4

Suyash Joshi
Tera Contributor

Hi @Saranya K 
Try this,

 

function onChangeAssignmentGroup() {
// Get the current value of the assignment group field
var assignmentGroup = g_form.getValue('assignment_group');

// Check if the assignment group has changed
if (g_form.modified && assignmentGroup) {
// Set the state to 'New'
g_form.setValue('state', '1'); // '1' represents the value for 'New'

// Disable the 'state' field to prevent further changes
g_form.setReadOnly('state', true);
}
}

If my suggestion are cleared your problem so you can accept my solution for other user benefit and also give helpfuls

Best Regards,

Suyash

Pratiksha2
Mega Sage

Hello @Saranya K 

Below is a modified version of the onchange client script, Please try and see if it works,

 

    var incState = g_form.getValue('state');
    if (newValue != oldValue && (incState == '2' || incState == '3'))
        g_form.setValue('state', 1);
}

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Pratiksha

Hi @Pratiksha2 ,

 

I have tried in that way also already if we write code like that the state field is showing '1' instead of 'new' before save

 

SaranyaK_0-1706013743183.png

 

 

Thanks

Hello @Saranya K ,
Please try below code, Also Please verify the backend value in the state field's previous choice for 'New.'

   var stateField = g_form.getControl('state');

    // Check if the incident is in progress
    var incidentState = g_form.getValue('state');
    if (incidentState === '2' || incidentState=='3') { // Assuming '2' is the code for 'In Progress'
        // Set the 'state' field to 'New'
        g_form.setValue('state', 'New');
    }

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Pratiksha