New field (Reassignment Reason) is visible/mandatory when assigned to is updated

ahmed-24
Giga Guru

i want to create a new field (Reassignement reason) which is (Visibile/mandatory) when the assigned to is updated 

Icreate a UI Policy whith script; i also create a client script. But it's not working!!

Help please. 

21 REPLIES 21

Can you please share screen shot of field on dictionary,UI Policy, form and the form layout?

Hi @ahmed-24, try the script I have shared, also disable any other customization to see if it works properly or not.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    //Type appropriate comment here, and begin script below
    var originalAssignedTo = g_form.getValue('assigned_to');
    g_form.setMandatory('u_reassignment_reason', false);
    g_form.setDisplay('u_reassignment_reason', false);
    if (newValue != oldValue) {
        g_form.setDisplay('u_reassignment_reason', true);
        g_form.setMandatory('u_reassignment_reason', true);
    } else {
        g_form.setMandatory('u_reassignment_reason', false);
        g_form.setDisplay('u_reassignment_reason', false);
    }
}

Regards,

Ehab Pilloor

Okay But as I can see here on the UI policy you have check Onload.
So based on your work this will run onload and that time its checking the script.

As I can also see we cant apply the direct chnage condition for Assigned to field from UI policy

But as per the requirement you can do like this:-
Create a Client Script:-

1.Name:-Set Reassignment Reason

2.Table:-Incident

3.Type:-Onchange

4.Field:-Assigned

5.Script:-

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	var newAssignee = g_form.getValue('assigned_to');
    if (newAssignee != oldValue) {
        // Show the Reassignment Reason field
		g_form.setValue('u_reassignment_reason','');
        g_form.setDisplay('u_reassignment_reason', true);

        // Make it mandatory
        g_form.setMandatory('u_reassignment_reason', true);

        // Optionally, clear the field to force new input
        g_form.setValue('u_reassignment_reason', '');
    } else {
        // Hide the field if Assigned to is cleared
        g_form.setMandatory('u_reassignment_reason', false);
        g_form.setValue('u_reassignment_reason', '');
		g_form.setDisplay('u_reassignment_reason', false);
    }



}

@Roshnee Dash The problem that the field is still visible before/after updating the assigned to. and the requirement is that field must appears just when we update  the assign to 

ahmed24_0-1750418211646.png