Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to compare mutiple sys ids?

Utkarsha
Tera Contributor

Hello experts,

I have written a BR to update a field on particular table based on metric_definition sys ids from asmt_metric_result table

I have stored around 27 sysids by putting , in between them...now the issue is there are three different values which i have to update for the target table field...how should i modify the conditions here could anyone please suggest me?



var grCompany = new GlideRecord('core_company');

   grCompany.addEncodedQuery('sys_id=');

   grCompany.query();

   gs.info("out-1");

   if (grCompany.next()) {

gs.info("inside");

 

       //Get the Assessment instances from the response of IRA

       var grInstance = new GlideRecord('asmt_assessment_instance');

       grInstance.addEncodedQuery('vdr_tiering_assessment=5b4');

       grInstance.query();

       gs.info("outside");

      

       if (grInstance.next()) {

gs.info("inside");

           var responses_data2 = gs.getProperty('sn_vdr_risk_asmt.Business data tier 2').split(',');

           //var responses_data3 = gs.getProperty('sn_vdr_risk_asmt.Business data Tier 3').split(',');

          // var responses_data1 = gs.getProperty('sn_vdr_risk_asmt.Business data Tier 1').split(',');

           //Get the locations selected as a part of users response

           var grAsmt = new GlideRecord('asmt_metric_result');

           grAsmt.addEncodedQuery('metric.nameSTARTSWITHIdentify each category of Uber data that the third party will collect, receive, store or disclose:^metric_definition.sys_idIN'+responses_data2);

           grAsmt.query();

gs.info("out");

           if (grAsmt.next()) {

gs.info("inside");

 

 

 

gs.info(responses_data2);

                   grCompany.u_business_data_tier = 'Tier 2';

                   grCompany.autoSysFields(false);

               grCompany.setWorkflow(false);

 

                   gs.info(" Updated Company   " + grCompany.name);

                   grCompany.update();

              

           }

               //} //else if (grAsmt.metric_definition ==responses_data3) {

                  // coreData.u_business_data_tier = 'Tier 3';

                   //coreData.autoSysFields(false);

                   //coreData.setWorkflow(false);

 

                   // gs.info(" Updated Company   " + coreData.name);

                   //coreData.update();

              // } else if (grAsmt.metric_definition == responses_data1) {

                  // coreData.u_business_data_tier = 'Tier 1';

                   //coreData.autoSysFields(false);

                   //coreData.setWorkflow(false);

 

                   // gs.info(" Updated Company   " + coreData.name);

                  // coreData.update();

               //}

 

 

          // }

      // }

   }

       }
I have commented the below lines which are not working
Any kind of help here is greatly appreciated

Thank you

1 ACCEPTED SOLUTION

AniketC85155510
Kilo Patron

Hello @Utkarsha  ,

Please give a try to the modified script below and see how it works for you.

var grCompany = new GlideRecord('core_company');
grCompany.addEncodedQuery('sys_id=');
grCompany.query();

if (grCompany.next()) {
    var grInstance = new GlideRecord('asmt_assessment_instance');
    grInstance.addEncodedQuery('vdr_tiering_assessment=5b4');
    grInstance.query();

    if (grInstance.next()) {
        var responses_data2 = gs.getProperty('sn_vdr_risk_asmt.Business data tier 2').split(',');

        var grAsmt = new GlideRecord('asmt_metric_result');
        grAsmt.addEncodedQuery('metric.nameSTARTSWITHIdentify each category of Uber data that the third party will collect, receive, store or disclose:^metric_definition.sys_idIN' + responses_data2);
        grAsmt.query();

        while (grAsmt.next()) {
            // Check if the metric_definition.sys_id is in the list of responses_data2
            if (responses_data2.indexOf(grAsmt.metric_definition.sys_id.toString()) !== -1) {
                grCompany.u_business_data_tier = 'Tier 2';
                grCompany.autoSysFields(false);
                grCompany.setWorkflow(false);
                gs.info("Updated Company " + grCompany.name);
                grCompany.update();
            }
        }
    }
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

View solution in original post

1 REPLY 1

AniketC85155510
Kilo Patron

Hello @Utkarsha  ,

Please give a try to the modified script below and see how it works for you.

var grCompany = new GlideRecord('core_company');
grCompany.addEncodedQuery('sys_id=');
grCompany.query();

if (grCompany.next()) {
    var grInstance = new GlideRecord('asmt_assessment_instance');
    grInstance.addEncodedQuery('vdr_tiering_assessment=5b4');
    grInstance.query();

    if (grInstance.next()) {
        var responses_data2 = gs.getProperty('sn_vdr_risk_asmt.Business data tier 2').split(',');

        var grAsmt = new GlideRecord('asmt_metric_result');
        grAsmt.addEncodedQuery('metric.nameSTARTSWITHIdentify each category of Uber data that the third party will collect, receive, store or disclose:^metric_definition.sys_idIN' + responses_data2);
        grAsmt.query();

        while (grAsmt.next()) {
            // Check if the metric_definition.sys_id is in the list of responses_data2
            if (responses_data2.indexOf(grAsmt.metric_definition.sys_id.toString()) !== -1) {
                grCompany.u_business_data_tier = 'Tier 2';
                grCompany.autoSysFields(false);
                grCompany.setWorkflow(false);
                gs.info("Updated Company " + grCompany.name);
                grCompany.update();
            }
        }
    }
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket