- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2022 07:15 AM
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!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2022 08:01 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2022 08:01 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2022 08:41 AM
to build on - you don't need the .addQuery() statements, as they are empty.
and you can safely replace the true and false strings with boolean true false values
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2022 12:59 PM
Hi
I am debugging now. Thanks for pointing out the parameter issue. The .addQuery() statements are there because when working from a case in Agent workspace the agents have the ability to create Incidents and Requests from those cases. If they do so, it then applies the case number to the parent field of those tasks. Which is why you have:
If incident.parent is not empty OR if the incident.parent sys ID matches the current caseID then "True"
same with the Request.
If both of these are true, then I don't want to trigger the survey. If false, then trigger the survey. Although I am kind of new, do you have any idea what that code would look like in the BR or SI? Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2022 01:17 PM
This is not a valid statement:
grIncident.addQuery();
This one neither
grRequest.addQuery();
....
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024