Implimentation of Align Categories and Close Codes of Case based on Product

Dinesh87
Tera Expert

Hello

 

What is my goal?
(1) To have close category and close code values that are available for the *product* selected on the case.
(2) Have a many to one selection of close codes for any close category. For example, If the close category is ‘Hardware Failure’ someone should be able to select ‘DOA’ and ‘Fan’ as the close codes.
Just for Information: - There are around 90k products and Close category with 15choices and Close codes with 200choices.

What I am looking for is we need to have close category to be populated when product is selected which are related to that product.
And I also want to select the close code as multiple options.
If you have an idea about it, please respond to this and provide your solution ASAP!

Thanks in Advance!
Dinesh


1 ACCEPTED SOLUTION

Hi @Dinesh87 ,

 

If the Product is a reference field, here’s what you can do:

Step 1: Create a custom field in the relevant table and name it something like "Link Close Category." In this field, specify the Close Category for each product record.

 

Step 2: Repeat the same process for the Close Code list field (which I believe also refers to a table). Create a new field and provide the Close Category for each Close Code record.

Once you’ve linked the Product to the Close Category and the Close Code to the Close Category via the custom fields, you can then create two OnChange client scripts: one for the Product field and another for the Close Category field.

 

Here’s the code for the Product:

Client Callable Script Include:

 

 

var PopulateCategory = Class.create();
PopulateCategory.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getCategory: function() {
        var code = this.getParameter('sysparm_product');
        var codeCategory = new GlideRecord('product table name');
        codeCategory.addQuery("Product_name", 'code'); //  provide product name which you have select
        codeCategory.query();
        if (codeCategory.next()) {
            return codeCategory.u_link_close_category.toString(); // it will return linking close category
        } else {
            return "";
        }
    },
    type: 'PopulateCategory'
});

 

 

OnChange Client Script for the Product Field:

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var ga = new GlideAjax("PopulateCategory"); // Script Include Name - PopulateCategory
    ga.addParam('sysparm_name', 'getCategory');
    ga.addParam('sysparm_code', newValue); // newValue hold product name
    ga.getXMLAnswer(getCategory);
    function getCategory(answer) {
        if (answer)
            g_form.setValue('category', answer);
    }
}

 

 

You can adjust the scripts as needed for your requirements. The same approach can be applied for populating the Close Code using a client script on the Category field.

 

 

We would appreciate it if you could mark this solution as correct and helpful. Your feedback encourages us to continue providing support in the future!

 

Regards

Moin

 

 

View solution in original post

4 REPLIES 4

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Dinesh87 

You can create a reference field and a list collector ( to select multi values) and you can filter based upon the product 

 

 

regards 

Sai venkatesh 

Moin Kazi
Kilo Sage
Kilo Sage

Hi @Dinesh87 ,

 

What type is your product field, and how is each product linked to its close category?

If you have clear details on this, you can create an onChange Client Script for the product field. Use GlideAjax to call a Script Include where you pass the product information from the client script.

 

If your product field is a reference field, you can query that table to find the related close categories and return them to the client side. On the other hand, if the product field is choice-based, you can use the sys_choice table and leverage the dependent choices to retrieve the close categories, which you can then populate in the close category field.

 

You can apply the same approach for the close code field. In this case, send the close category details to the Script Include and return the close codes, which can then be populated in the close code field in ServiceNow.

 

I hope this helps!

 

Regards,
Moin

Hello @Moin Kazi 
Thanks for sharing that
Product field is Reference field and Close category field is choice field and Close code field is List because i have to select multiple options in it.
At present I have no idea about the process or approach to move with. I believe there no such linkage as of now for product and close category.It would be so much helpful if you can provide something more clear and process. So, that I can work on it.

Thanks in Advance!
Dinesh.

Hi @Dinesh87 ,

 

If the Product is a reference field, here’s what you can do:

Step 1: Create a custom field in the relevant table and name it something like "Link Close Category." In this field, specify the Close Category for each product record.

 

Step 2: Repeat the same process for the Close Code list field (which I believe also refers to a table). Create a new field and provide the Close Category for each Close Code record.

Once you’ve linked the Product to the Close Category and the Close Code to the Close Category via the custom fields, you can then create two OnChange client scripts: one for the Product field and another for the Close Category field.

 

Here’s the code for the Product:

Client Callable Script Include:

 

 

var PopulateCategory = Class.create();
PopulateCategory.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getCategory: function() {
        var code = this.getParameter('sysparm_product');
        var codeCategory = new GlideRecord('product table name');
        codeCategory.addQuery("Product_name", 'code'); //  provide product name which you have select
        codeCategory.query();
        if (codeCategory.next()) {
            return codeCategory.u_link_close_category.toString(); // it will return linking close category
        } else {
            return "";
        }
    },
    type: 'PopulateCategory'
});

 

 

OnChange Client Script for the Product Field:

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var ga = new GlideAjax("PopulateCategory"); // Script Include Name - PopulateCategory
    ga.addParam('sysparm_name', 'getCategory');
    ga.addParam('sysparm_code', newValue); // newValue hold product name
    ga.getXMLAnswer(getCategory);
    function getCategory(answer) {
        if (answer)
            g_form.setValue('category', answer);
    }
}

 

 

You can adjust the scripts as needed for your requirements. The same approach can be applied for populating the Close Code using a client script on the Category field.

 

 

We would appreciate it if you could mark this solution as correct and helpful. Your feedback encourages us to continue providing support in the future!

 

Regards

Moin