- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2017 05:47 AM
Hi All,
I have created a record producer to be used on a customer portal to create incidents. This has many variables, but the answer to 'what is the incident related to?' (inc_rel_to) decides which variables appear to the user to be answered.
I have add the Incident Variable Editor to the incident form, but I only want this to show the variables that have been answered - currently it displays all the variables on the record producer regardless of if these were visible when the ticket was submitted.
I have created the display business rule on the incident table:
I have also created the following client script:
However all the variables are displaying when I load an incident in the normal servicenow UI that has been created by my record producer.
Any help as to where I am going wrong will be greatly appreciated.
Thanks
Sam
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2017 09:24 AM
Sam, ok reworked the script. I found if I hid the container start and end fields, the entire variable formatter disappeared so I commented those lines out and added specific code NOT to hide them. I added code to hide the "mapped" fields as well. Here is my entire business rule script:
(function executeRule(current, previous /*null when async*/) {
var hideTypes = [];
hideTypes.push("11"); //Label
g_scratchpad.emptyVars = "";
var emptyVars = [];
var producerVars = new GlideRecord("question_answer");
producerVars.addQuery("table_sys_id", current.sys_id);
producerVars.query();
while (producerVars.next()) {
// First check to see if container and if so continue since hiding will cause issues
if (producerVars.question.type == "19" || producerVars.question.type == "20") {
continue;
}
// Second check to see if variable type is one we always want to hide
if (hideTypes.indexOf(producerVars.question.type) > -1) {
emptyVars.push(producerVars.question.name.toString());
continue;
}
// Third check if variable is mapped to field, if so skip it
if (producerVars.question.map_to_field == true) {
emptyVars.push(producerVars.question.name.toString());
continue;
}
// Fourth skip any variable with a Null value
if (gs.nil(producerVars.value)) {
emptyVars.push(producerVars.question.name.toString());
continue;
}
// Fifth check if variable is a checkbox and hide if default value of false
if (producerVars.question.type == "7" && producerVars.value == "false") {
emptyVars.push(producerVars.question.name.toString());
continue;
}
}
g_scratchpad.emptyVars = emptyVars.join();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2018 07:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2018 08:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2018 11:35 AM
Sam the blank value you mention appears to be a dash '-'. That could be causing an error and the script fails to run. I updated the script to check for that and abort pushing it to the emptyVars array. Maybe this will fix the issue:
(function executeRule(current, previous /*null when async*/) {
var hideTypes = [];
//hideTypes.push("11"); //Label
g_scratchpad.emptyVars = "";
var emptyVars = [];
var producerVars = new GlideRecord("question_answer");
producerVars.addQuery("table_sys_id", current.sys_id);
producerVars.query();
while (producerVars.next()) {
// First check to see if container and if so continue since hiding will cause issues
if (producerVars.question.type == "11" || producerVars.question.type == "19" || producerVars.question.type == "20") {
continue;
}
var variableName = producerVars.question.name.toString();
// Second check to make sure name has a value, if not continue
if (gs.nil(variableName) || variableName == "-") {
continue;
}
// Third check to see if variable type is one we always want to hide
if (hideTypes.indexOf(producerVars.question.type) > -1) {
emptyVars.push(variableName);
continue;
}
// Fourth check if variable is mapped to field, if so skip it
if (producerVars.question.map_to_field == true) {
emptyVars.push(variableName);
continue;
}
// Fifth skip any variable with a Null value
if (gs.nil(producerVars.value)) {
emptyVars.push(variableName);
continue;
}
// Sixth check if variable is a checkbox and hide if default value of false
if (producerVars.question.type == "7" && producerVars.value == "false") {
emptyVars.push(variableName);
continue;
}
}
g_scratchpad.emptyVars = emptyVars.join();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2017 06:15 AM
Hey Sam,
We use g_scratchpad variable in display business rule to store data from server side, so that we can use the data in client side later on. I hope you have used display business rule. As you are adding the variables in an array and retriveing the variables by spliting it. Some modification in the code:
g_scratchpad.emptyVars = [];
//same code as you have written
g_scratchpad.emptyVars = emptyVars;
in client script:
var emptyVars = g_scratchpad.emptyVars.toString().split(",");
Please let me know if your issue has been resolved.
Regards,
Souren