- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2023 01:39 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2023 11:22 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2023 06:11 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2023 06:41 AM
Thank you @Brad Bowman !
Here some additional info:
Tis is a part of the script (var- sets defined, two sets for now):
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:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2023 11:22 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2023 06:46 AM - edited ‎09-14-2023 06:47 AM
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.