Creating a BR to trigger a Survey for a Case that has no related Incident or Request

Jimmy45
Giga Guru

Hi Community,

 

I have a requirement.  A survey needs to be triggered by a business rule on the sn_customerservice_case table.  That's right, I want to trigger a survey to be sent out only when the case is resolved and it has no related incident or request. (parent)

So I created a business rule which points to a script include:

Business Rule:

    if (grSurvey.get(strAssessmentMetricTypeSysId)) {
        if (grSurvey.schedule_type == 'on_demand' &&
            grSurvey.evaluation_method == 'survey' &&
            grSurvey.publish_state != "draft" &&
            new AssessmentUtils().hasSurveyQuestions(grSurvey)) {
			var ifChildTicketExists = new CustomerSupportCaseMigrationUtil();
            var childticket = ifChildTicketExists.validateSurveyTrigger();
            var result = new SNC.AssessmentCreation().createAssessments(strAssessmentMetricTypeSysId, caseSysId, surveyRecipient);
           

 

Script Include:

CustomerSupportCaseMigrationUtil

var CustomerSupportCaseMigrationUtil = Class.create();
EndUserSupportCaseMigrationUtil.prototype = {
    initialize: function() {},


    validateSurveyTrigger: function(caseSysId, surveySysId) {
        var reqFlag;
        var incFlag;
        var grRequest = new GlideRecord('sc_request');
        grRequest.addQuery();
        grRequest.addEncodedQuery('parent!=NULL^parent.sys_id=' + caseSysId);
        grRequest.query();
        if (grRequest.getRowCount() > 0) reqFlag = 'true';


        var grIncident = new GlideRecord('incident');
        grIncident.addQuery();
        grIncident.addEncodedQuery('parent!=NULL^parent.sys_id=' + caseSysId);
        grIncident.query();
        if (grIncident.getRowCount() > 0) incFlag = 'true';

        if (reqFlag == 'true' || incFlag == 'true') {
            return "true";
        } else return "false";

    },
    type: 'CustomerSupportCaseMigrationUtil'
};

So what I am trying to achieve here is if the reqFlag or incFlag is False then to trigger the survey.  Right now when I put in a case and meet the requirements, the survey doesn't trigger.  Can someone show me where this isn't working or why?  Thank you all so much!

 

1 ACCEPTED SOLUTION

Martin Ivanov
Giga Sage
Giga Sage

hi. I don't see any debug messages here. Put such to track the execution of the script. Try to debug somehow. 

Looking at your code - in the script include, your function expects two parameters (caseSysId, surveySysId) which you are then using inside the code. However, when you are calling this function in the business rule, you are not passing these parameters. This way, it is totally expected that the script include will not work. 

try to fix these and you will be one step closer. 

Please Mark Correct AND Helpful. Thanks!

Martin Ivanov
2022 Community Rising Star


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

View solution in original post

5 REPLIES 5

Martin Ivanov
Giga Sage
Giga Sage

Hi. If your issue is resolved and my response has helped, plese consider marking Correct and Helpful. Thanks!

Martin Ivanov

2022 Community Rising Star

 


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024