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

Community Alums
Not applicable

Hi @BijoyDeb ,

Did you also checked for any ACLs running, speacially write ACL on this table?

 

Hi @Community Alums ,

Yes, I checked ACLs around this choice field on incident, even me as an admin facing same issue on workspace only

 

Ankur Bawiskar
Tera Patron
Tera Patron

@BijoyDeb 

any client script is running only on workspace view which is clearing?

Also subcategory choice is dependent on category choice

how are you making it dependent on Service offering?

share the relevant scripts along with their screenshots.

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

Hi @Ankur Bawiskar ,

We have used Service offering name as dependent field for subcategory.

 

Below are client scripts that runs on incident-

 

1. When we change the value of the Configuration Item field, below client script runs which sets values for Service, service offering and Category

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']);
       
    }


}
 
2. If the Category field value was changed, below client scripts runs to populate service and service offering

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(newValue == 'reporting_analytics'
            || newValue == 'integrations_devops'
            || newValue == 'gtm_applications'
            || newValue == 'finance_applications'
            || newValue == 'it_operations_engineering'
            || newValue == 'hardware'
            || newValue == 'enterprise_software_tools'){
       
        //var categoryLabel = g_form.getOption('category', newValue).text;
        //alert(g_form.getDisplayValue('category'));
        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');
       // var arr = JSON.parse(answer);
        g_form.setValue('business_service', ''+answer);
        g_form.clearValue('service_offering');
        g_form.clearValue('cmdb_ci');
       g_form.clearValue('subcategory');
    }



   

}
 
 
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 '';
    }
    else if(newValue != 'reporting_analytics'
            && newValue != 'integrations_devops'
            && newValue != 'gtm_applications'
            && newValue != 'finance_applications'
            && newValue != 'it_operations_engineering'
            && newValue != 'hardware'
            && newValue != 'enterprise_software_tools'
            && !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 answer = response.responseXML.documentElement.getAttribute('answer');
        var arr = JSON.parse(response);
        //alert(arr['service'] + " " + arr['service_offering']);
        //g_scratchpad.cmd_ciChanged = true;
        g_form.setValue('business_service', arr['service']);
        g_form.setValue('service_offering', arr['service_offering']);
       g_form.clearValue('subcategory');
    }
}