- 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
11-14-2017 05:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2017 07:48 AM
Sam, I just replicated the issue on my demo instance and the issue is caused by hiding the label. The variable UI uses the label above checkboxes like a container so if you hide the label then all the checkboxes get hidden as well. Programmatically it will be difficult to come up with code to dynamically hide the label if none of the checkboxes are checked. Its definitely possible but would require more time than I have to help in a community setting.
I ended up commenting out the label:
//hideTypes.push("11"); //Label
Then I added 11 to the exclusion list:
if (producerVars.question.type == "11" || producerVars.question.type == "19" || producerVars.question.type == "20") {
continue;
}
Once I did that the checkboxes showed up and only the ones that I had checked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2017 08:23 AM
Thanks for the above Michael and all your help.
I've just tried this, and the checkboxes now appear, but also all the other labels that I'd like not to appear also show.
I'll mark this question as answered, and start a new one to see if can come up with the finial issue.
Thanks once again for all your time and effort on this.
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 10:18 AM
Hi Michael,
Thanks for this.
Can I just ask if there's any reason this wouldn't work in a scoped app? The BR is a scoped Display BR is that the right way to do this?
Cheers,
Nabeel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2018 07:40 AM
Hi Michael,
We've recently upgraded to kingston patch 8 and the variable editor is no longer hiding the blank fields.
Any suggestions?
I've added an alert on the client script and can see the scratchpad contains the variables.
Thanks