Choice field value getting cleared out on workspace after saving the form

BijoyDeb
Tera Contributor

Hello all,

I am facing an issue on custom workspaces if I try to update incidents on them.

So, as per our existing logic, whenever someone changes CI field on incident, it will set values for Category, Service, Service offering and subcategory will becomes mandatory to select values from dropdown.

(Subcategory is dependent on Service offering names).

If i select any subcategory and save the form it works fine in native view.

But if I change CI on workspace for an incident, select subcategory and save the form, form will get saved (updating in server as well) but subcategory again becomes mandatory with no values to select.

 

I've checked all UI policies and client scripts around subcategory, but none of them is causing this issue.

if it would have caused, then in native view as well same issue could have been seen.

 

Can you please help me in debugging this issue?

8 REPLIES 8

@BijoyDeb 

so what debugging did you do?

None of your onchange will run after saving i.e. when form loads

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

Actually these are the client scripts around subcategory field, hence I shared here.

I checked for UI policies/ client scripts on incident if any of them clearing value of subcategory on  load, but didn't found any.

And as this value is not cleared from server (this I validate by opening incident in workspace and native view side by side, updated ci and saved subcategory which was visible in XML from native view)

@BijoyDeb 

Sorry but we don't have access to your instance and scripts.

You can add alert and see in client script

try this

1st script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }
    if (newValue === '') {
        g_form.clearValue('service_offering');
        return;
    }
    var category = g_form.getValue('category');
    if (category != 'hardware' && category != 'it_operations_engineering') {
        var grserof = new GlideAjax('GetIncidentDetails');
        grserof.addParam('sysparm_name', 'getRelatedServiceOffering');
        grserof.addParam('sysparam_ci', '' + newValue);
        grserof.getXMLAnswer(checkdetails);
    }

    function checkdetails(answer) {
        var arr = JSON.parse(answer);
        g_scratchpad.cmd_ciChanged = true;

        if (arr['category']) {
            g_form.setValue('category', '' + arr['category']);
        } else if (arr['so_category']) {
            g_form.setValue('category', '' + arr['so_category']);
        }

        g_form.setValue('business_service', '' + arr['service']);
        g_form.setValue('service_offering', '' + arr['service_offing']);
    }
}

2nd one

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }
    if (newValue == '') {
        g_form.clearValue('business_service');
        g_form.clearValue('service_offering');
        g_form.clearValue('cmdb_ci');
        g_form.clearValue('subcategory');
        return '';
    }
    if (g_scratchpad.cmd_ciChanged) {
        g_scratchpad.cmd_ciChanged = false;
    } else if (['reporting_analytics', 'integrations_devops', 'gtm_applications', 'finance_applications', 'it_operations_engineering', 'hardware', 'enterprise_software_tools'].includes(newValue)) {
        var category = '' + newValue;
        var grser = new GlideAjax('GetIncidentDetails');
        grser.addParam('sysparm_name', 'getRelatedService');
        grser.addParam('sysparam_category', '' + category);
        grser.getXML(updateDetails);
    }

    function updateDetails(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        g_form.setValue('business_service', '' + answer);
        g_form.clearValue('service_offering');
        g_form.clearValue('cmdb_ci');
        g_form.clearValue('subcategory');
    }
}

3rd on change - on category (alternative)

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }
    if (newValue == '') {
        g_form.clearValue('business_service');
        g_form.clearValue('service_offering');
        g_form.clearValue('cmdb_ci');
        g_form.clearValue('subcategory');
        return '';
    } else if (!['reporting_analytics', 'integrations_devops', 'gtm_applications', 'finance_applications', 'it_operations_engineering', 'hardware', 'enterprise_software_tools'].includes(newValue) && !g_scratchpad.cmd_ciChanged) {
        var category = '' + newValue;
        var grser = new GlideAjax('GetIncidentDetails');
        grser.addParam('sysparm_name', 'getCatServiceOffering');
        grser.addParam('sysparam_category', '' + category);
        grser.getXMLAnswer(updateDetails);
    } else if (newValue && newValue != oldValue && !g_scratchpad.cmd_ciChanged) {
        g_form.clearValue('service_offering');
        g_form.clearValue('subcategory');
    }

    function updateDetails(response) {
        var arr = JSON.parse(response);
        g_form.setValue('business_service', arr['service']);
        g_form.setValue('service_offering', arr['service_offering']);
        g_form.clearValue('subcategory');
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@BijoyDeb 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader