Based on checkbox field value, I need to set variables value true or false?

varma2
Mega Sage

Hi All,

We have software model published catalog items and all the software models stored in ''cmdb_software_product_model'' table.

In this table we have two check box 1 is pre installation 2nd is post installation. please refer the below screenshot of both fields,

find_real_file.png

 

We have catlog items in these models and we have a two variables same as pre installation and post installation.

If above fields is checked in software model  it will need to show below variable as a TRUE and if field not checked it will show false in below variables.

find_real_file.png

Please suggest me on this.

 

Thanks,

Varma 

1 ACCEPTED SOLUTION

@varma

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark my response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

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

View solution in original post

19 REPLIES 19

Hi,

approach will be the same.

onChange of that string variable use GlideAjax and query the software model table to check those 2 checkboxes

Based on that set the 2 variables

Regards
Ankur

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

Hi Ankur,

 

could you please suggest code. That will be very helpful.

 

 

Thanks,

Varma

Hi,

sample below

Script Include: It should be client callable

var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
    checkRecordPresent: function(){

        var name = this.getParameter('sysparm_name');
        var obj = {};
        var gr = new GlideRecord('software model table'); // give proper table name here
        gr.addQuery('field', name); // use valid field name here
        gr.query();
        if(gr.next()){
            obj["pre"] = gr.pre_installation.toString();
            obj["post"] = gr.post_installation.toString()
        }
        JSON.stringify(obj);
    },
    
    type: 'checkRecords'
});

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var ga = new GlideAjax('checkRecords');
    ga.addParam('sysparm_name', "checkRecordPresent");
    ga.addParam('sysparm_name', g_form.getValue('build_version')); // give here valid variable name
    ga.getXMLAnswer(function(answer){
        if(answer != ''){
            var parser = JSON.parse(answer);
            g_form.setValue('pre_variable', parser.pre); // give here valid variable name
            g_form.setValue('post_variable', parser.post); // give here valid variable name
        }
    });
    //Type appropriate comment here, and begin script below

}

Regards
Ankur

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

Hi Ankur,

 

Thanks for you help,

 

I have tried the above code but its triggering error like this ''There is a JavaScript error in your browser console''

And also i came to know ''Build version '' value is not change its constant. 

Below screenshot which i configured

find_real_file.png

 

Client script:

find_real_file.png

With referencing any variable cant we get the field value?

Please suggest,

 

Thanks,

Varma 

Hi,

Are you querying with proper field on software model table?

User is giving build version and you are trying to search in that field?

Try adding alert what came in answer

alert(answer);

Regards
Ankur

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