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

I tried this script now, but sadly it doesn't write anyting down in the Description- field of the Incident. 
I have no idea what it could be. Everything seems to be OK.

It works, thanks! The problem I had with this script was that I put the "VAR sets" above in the script, instead of below the "}" somewhere further down the script.

Good to hear, and you are welcome!