Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

In OOB data certification task, if we certify any element then the respective CI in cmdb_ci table should display value "certified" for the custom field ''datacertificationstatus" in cmdb_ci table

Sachin Gavhane
Giga Guru

Step 1 : I have created a custom field named "datacertificationstatus" on cmdb_ci table

Step 2 : In OOB data certification task, if any element is certified then associated CIs in cmdb_ci table should display value as "certified" for the above custom field created in cmdb_ci table

find_real_file.png

if we certify above elements then respective CIs in cmdb_ci table should display value as "certified" for the custom field "datacertificationstatus" in cmdb_ci table

1 ACCEPTED SOLUTION

Hi @Sachin Gavhane 

There was a flaw in the script shared before where I forgot to pass the parameter correctly when it need to be certified.

So have updated the script , please use the same and test. I have tested it and works fine for me now.

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var getCI = current.id;
    var gettargetTable = current.table;

    var getAllDetails = CheckCIColumn(getCI);
    if (getAllDetails == true) {
        updateCI(gettargetTable,getCI);
    }

    function CheckCIColumn(CI) {
        var gr = new GlideRecord('cert_audit_result');
        gr.addQuery('id', CI);
        gr.addQuery('state','Pending'); // This will check if there are any un Certified records or not.
        gr.query();
        if (gr.next()) {
            gs.info('There are still record which are not certified. So please certify first');
			return false;
        }else{
			return true;
		}
    }

    function updateCI(gettargetTable,getCI) {
        var gr = new GlideRecord(gettargetTable);
        gr.addQuery('sys_id', getCI);
        gr.query();
        if (gr.next()) {
            gr.short_description = 'certified'; // Please make sure to replace "certified" with its correct back end value here and and also replace "FieldName" with the correct field name which you want to set.
            gr.update();
        }
    }



})(current, previous);

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

17 REPLIES 17

Hi @Sachin Gavhane 

There was a flaw in the script shared before where I forgot to pass the parameter correctly when it need to be certified.

So have updated the script , please use the same and test. I have tested it and works fine for me now.

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var getCI = current.id;
    var gettargetTable = current.table;

    var getAllDetails = CheckCIColumn(getCI);
    if (getAllDetails == true) {
        updateCI(gettargetTable,getCI);
    }

    function CheckCIColumn(CI) {
        var gr = new GlideRecord('cert_audit_result');
        gr.addQuery('id', CI);
        gr.addQuery('state','Pending'); // This will check if there are any un Certified records or not.
        gr.query();
        if (gr.next()) {
            gs.info('There are still record which are not certified. So please certify first');
			return false;
        }else{
			return true;
		}
    }

    function updateCI(gettargetTable,getCI) {
        var gr = new GlideRecord(gettargetTable);
        gr.addQuery('sys_id', getCI);
        gr.query();
        if (gr.next()) {
            gr.short_description = 'certified'; // Please make sure to replace "certified" with its correct back end value here and and also replace "FieldName" with the correct field name which you want to set.
            gr.update();
        }
    }



})(current, previous);

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi @shloke04 

I have modified ur script and it is as follows

find_real_file.png

it is working perfect.

Thanks for your help for this requirement

Afternoon.  A few questions.

1. Where was your original script placed/written in the system?  BR?

2. Why is the Cert instance/Task NOT marking cmdb_ci_business_app records certified out of box?