How to hide or delete empty Record Producer fields (variables) in Incident Description field?

AdamUMC
Giga Guru

Hello there,


I have a Service Portal Incident form (Record Producer), with several fields (variables).
I write this fields through a script, to the Incident "Description"- field.

Now I want to NOT include the fields that were NOT filled in in the Service Portal Incident form.
Is it possible to do that easy by an extra script addition and how?


Thanks very much and all best!

1 ACCEPTED SOLUTION

If the variables are defined in the Record Producer within a single row variable set, there is no difference in the syntax than if they were not in a variable set.  If they are in a multi-row variable set, that's a different story.  Assuming your question1 yes/no lines are working to dump the correct variables into the description field, you would stick with the same syntax to not print the blank variables.  There might be a better way to do this, but something like:

var cn = '';
var fieldb = '';
var fieldc = '';
var fieldd = '';
var fielde = '';
var field1 = '';
var field2 = '';
var field3 = '';
var field4 = '';
if (producer.computername.getDisplayValue() != '') {
    cn = 'Computername: ' + producer.computername.getDisplayValue()  + "\n";
} 
if (producer.fieldb != '') {
    fieldb = 'Field B: ' + producer.fieldb + "\n";
}

// create an if block for each of the other variables ...

var description_set_1 = cn + fieldb + fieldc + fieldd + fielde;
var description_set_2 = cn + field1 + field2 + field3 + field4;

if (producer.question1 == 'yes') {
    current.description = description_set_1;
} else {
    current.description = description_set_2;
}

 

View solution in original post

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

Without seeing the script, the first thing that comes to mind is to check the value of each variable, only writing it to the Description field if it is not empty.

AdamUMC
Giga Guru

Thank you @Brad Bowman  !

Here some additional info:
Tis is a part of the script (var- sets defined, two sets for now):

AdamUMC_0-1694611978471.png


This part of the script determines if var set 1 of var set 2 will be used and processed to the Description- field of the Incident:

AdamUMC_1-1694612381399.png


I tried things like;
if ($('.producer.computername.getDisplayValue()').is(":empty")){
$('.producer.computername.getDisplayValue()').hide();

if ($('.producer.fieldb').is(":empty")){
$('.producer.fieldb').hide();

if ($('.fieldc').is(":empty")){
$('.fieldc').hide();

etc. but this does not work. Probably because my fields are bundled within a var -set.

If the variables are defined in the Record Producer within a single row variable set, there is no difference in the syntax than if they were not in a variable set.  If they are in a multi-row variable set, that's a different story.  Assuming your question1 yes/no lines are working to dump the correct variables into the description field, you would stick with the same syntax to not print the blank variables.  There might be a better way to do this, but something like:

var cn = '';
var fieldb = '';
var fieldc = '';
var fieldd = '';
var fielde = '';
var field1 = '';
var field2 = '';
var field3 = '';
var field4 = '';
if (producer.computername.getDisplayValue() != '') {
    cn = 'Computername: ' + producer.computername.getDisplayValue()  + "\n";
} 
if (producer.fieldb != '') {
    fieldb = 'Field B: ' + producer.fieldb + "\n";
}

// create an if block for each of the other variables ...

var description_set_1 = cn + fieldb + fieldc + fieldd + fielde;
var description_set_2 = cn + field1 + field2 + field3 + field4;

if (producer.question1 == 'yes') {
    current.description = description_set_1;
} else {
    current.description = description_set_2;
}

 

Thank you very much Brad! Sorry for my late reply, very busy.

I think I understand your sample script, and will try it here a.s.a.p. Thanks! If it works, I will obvious mark your post as Solution.