Record producer script for displaying variables set 'variable' in the incident description

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 08:12 AM
Hi,
I need assistance with a script below: I want to be able to display field1 or field-1 or field--1 based on user input and display it in the description of the record producer incident. if user input is red from field1, it should display field 1 and not the other fields because user did not select them.
so if field1 is has "blue, red"
and field-1 has "green, black"
and field --1 has "grey, yellow"
current.description = "Questions and Answers:" +
"\n" + "--------------------------------" +
"\n\n" + "Affected User: " + producer.on_behalf_o.getDisplayValue() + "" +
"\n" + "Country: " + producer.u_country.getDisplayValue() + "" +
"\n" + "Business Unit: " + producer.u_field1.getDisplayValue() + "" +
"\n" + "Business Unit: " + producer.u_field-1.getDisplayValue() + "" +
"\n" + "Business Unit: " + producer.u_field--1.getDisplayValue() + "" +
The script must not show the other fields id user did not select them it must only show 1 field. They cant all show because business unit is dependent on which country the user selects.
Regards
C

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 12:08 PM
Hello @Community Alums
Can you please try the below code...
var description = "Questions and Answers:" +
"\n" + "--------------------------------" +
"\n\n" + "Affected User: " + producer.on_behalf_o.getDisplayValue() + "" +
"\n" + "Country: " + producer.u_country.getDisplayValue() + "";
// Check user input and display the selected field
var userInput = producer.user_input; // Replace 'user_input' with the actual name of the field where the user selects the field (e.g., 'field_selection')
if (userInput == 'field1') {
description += "\n" + "Business Unit: " + producer.u_field1.getDisplayValue();
} else if (userInput == 'field-1') {
description += "\n" + "Business Unit: " + producer.u_field_1.getDisplayValue();
} else if (userInput == 'field--1') {
description += "\n" + "Business Unit: " + producer.u_field__1.getDisplayValue();
} else {
description += "\n" + "No Business Unit Selected"; // Provide a default message if none of the fields is selected
}
current.description = description;
Don't forget to mark my answer as Correct & Helpful, if applicable.
Krishna Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 01:58 AM
"\n" + "Severity: " + producer.u_severity + "" +
"\n" + "Number of Impacted Users: " + producer.number_of_impacted_users + "" +

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 02:11 AM
Hi,
Is this your complete script as the ending does not look right.
SEcndly, add logs to debug where the control is failing. Here is how you can debug. Made few changes to yoru script, plz check.
current.description = "Questions and Answers:" +
"\n" + "--------------------------------" +
"\n\n" + "Affected User: " + producer.on_behalf_o.getDisplayValue() + "" +
"\n" + "Country: " + producer.u_country.getDisplayValue() + "" ;
var SAbu = producer.u_business_area.toString();
var ARObu = producer.u_business_area_1.toString();
gs.info("Testing "+SAbu+"-----"+ARObu);
if (SAbu == 'u_business_area') {
gs.info("Testing SAbu If Entered here");
description += "\n" + "Business Unit: " + producer.u_business_area.getDisplayValue();
} else if (ARObu == 'u_business_area_1') {
gs.info("Testing ARObu If Entered here");
description += "\n" + "Business Unit: " + producer.u_business_area_1.getDisplayValue();
} else {
gs.info("Testing else If Entered here");
description += "\n" + "No Business Unit Selected";
}
// Check user input and display the selected field
var userInput = producer.business_unit_1;
if (userInput == 'business_unit_1') {
description += "\n" + "Business Unit: " + producer.business_unit_1.getDisplayValue();
} else if (userInput == 'business_unit_2') {
description += "\n" + "Business Unit: " + producer.business_unit_2.getDisplayValue();
} else if (userInput == 'business_unit_3') {
description += "\n" + "Business Unit: " + producer.business_unit_3.getDisplayValue();
} else if (userInput == 'business_unit_4') {
description += "\n" + "Business Unit: " + producer.business_unit_4.getDisplayValue();
} else if (userInput == 'business_unit_5') {
description += "\n" + "Business Unit: " + producer.business_unit_5.getDisplayValue();
} else {
description += "\n" + "No Business Unit Selected"; // Provide a default message if none of the fields is selected
}
"\n" + "Incident Type: " + producer.u_incident_type + "" +
"\n" + "Severity: " + producer.u_severity + "" +
"\n" + "Number of Impacted Users: " + producer.number_of_impacted_users + "" ;
Mark the comment as a correct answer and helpful if this has helped to solve the problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 07:34 AM
Hi,
Do le me know if this has solved the probelm or if you are facing any issue? If the answer is resolved, kindly mark my comment as a correct answer.