- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 03:29 AM - edited 07-25-2023 04:02 AM
Hi,
I am somehow going crazy in trying to solve something.
Scenario 1: I was creating a record producer with questions for the user to fill out. It shall create an incident when submitted
For the tables I have, I mapped them to the choice fields, so this will be auto filled out in the record later.
I also have questions like Date/Time, which I mapped to the work notes, for example, so that the data in the values will not get lost.
Now I have an option picker with 3 options. But even when I map them to work notes all I see there are the true/false values. I would love to have the description of every question in there as well. How to do that? I don't need 3 work notes with true/false or yes/no without even knowing which variable this now is meant to be.
Also no need to say that the checkbox/choice options I have will not be create as an own table field, because this record producer item is not visible to everyone in the end later, and the data doesn't need to be evaluated further. It's just seen as additional information.
In Scenrario 2 I tried the same thing, but with a catalogue item. But then I realised when creating the flow for the item, that catalogue items always produce a REQ and RITM, which I don't need as it shall be an incident.
When I create the flow to create a record I can't fetch the data that was entered in the catalogue item. Or can I?
I hope you understand my gibberish.. but I am going insane in trying how to solve this.
Thanks in advance. In case you need further info, let me know.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 06:50 AM
Hi Riya,
thanks for your detailed and smart answer but we solved it in a bit easier way for us that still did the trick!
For everyone else interested:
What we did now is to remove the mapping to the work notes for all fields in the record producer questions we used earlier and stayed with the check boxes, so we had
Option 1 [ ]
Option 2 [ ]
Option 3 [ ]
for the options we wanted to use.
Then we created a flow with the creation of this particular incident as the trigger (we added a default value in the record producer for the short description and hid the field for user so we could filter them out) and grabbed the values out of all variables from the record producer catalogue item ("Get catalogue Variables from" action). Of course the check boxes are still true/fale, though.
However, with these variables we update the incident record ("Update incident record" action) within the flow and just add the option text manually. And these will then be mapped to work notes. And voilá - I have everything I needed in the work notes written like:
Option 1: false
Option 2: true
Option 3: true
Needed a bit of thinking but it worked out smoothly.
Maybe this may help other people struggling with it in the future.
Best regards
Elena
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:53 AM
Hi @ehgebla ,
Hope you are doing great.
Scenario 1:
To display the description of each question in the work notes when using an option picker with 3 options, you can use "Client Scripts" to achieve this. Client Scripts are used to configure the behavior of forms and form fields in ServiceNow. Here's how you can do it:
Navigate to the record producer in ServiceNow and open it for editing.
Under the "Client Scripts" tab, click on "New" to create a new Client Script.
Set the "Applies to" field to the name of your record producer (e.g., Incident).
In the "Script" field, write JavaScript code that retrieves the description of the chosen option and appends it to the work notes. For example:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var optionPickerField = g_form.getControl('<name_of_your_option_picker_field>');
var description = '';
switch (newValue) {
case 'option1':
description = 'Description for Option 1';
break;
case 'option2':
description = 'Description for Option 2';
break;
case 'option3':
description = 'Description for Option 3';
break;
default:
description = 'Description not found';
break;
}
g_form.setValue('<name_of_your_work_notes_field>', description);
}
Scenario 2:
To capture the data entered in the catalogue item and create an incident without generating REQ and RITM, you can use "Business Rules" and "Script Includes." Business Rules allow you to perform server-side actions when a record is inserted, updated, or deleted, and Script Includes contain reusable JavaScript functions.
- Create a new Script Include.
var IncidentUtils = Class.create();
IncidentUtils.prototype = {
initialize: function() {},
createIncident: function(catalogItem, requestedFor, shortDescription, additionalInfo) {
var incident = new GlideRecord('incident');
incident.initialize();
incident.caller_id = requestedFor;
incident.short_description = shortDescription;
incident.additional_info = additionalInfo; // Additional information from the catalog item.
incident.insert();
return incident;
},
type: 'IncidentUtils'
};
- Create a new Business Rule, Set the "When" condition to "Before" and choose "Insert.", Set the "Current Table" to the name of your catalog item table (e.g., sc_cat_item).
(function executeRule(current, previous /*null when async*/) {
var shortDescription = current.short_description;
var additionalInfo = current.additional_info;
var requestedFor = current.requested_for;
var incidentUtils = new IncidentUtils();
var incident = incidentUtils.createIncident(current, requestedFor, shortDescription, additionalInfo);
current.setAbortAction(true); // Abort the current catalog item creation process.
})(current, previous);
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 06:50 AM
Hi Riya,
thanks for your detailed and smart answer but we solved it in a bit easier way for us that still did the trick!
For everyone else interested:
What we did now is to remove the mapping to the work notes for all fields in the record producer questions we used earlier and stayed with the check boxes, so we had
Option 1 [ ]
Option 2 [ ]
Option 3 [ ]
for the options we wanted to use.
Then we created a flow with the creation of this particular incident as the trigger (we added a default value in the record producer for the short description and hid the field for user so we could filter them out) and grabbed the values out of all variables from the record producer catalogue item ("Get catalogue Variables from" action). Of course the check boxes are still true/fale, though.
However, with these variables we update the incident record ("Update incident record" action) within the flow and just add the option text manually. And these will then be mapped to work notes. And voilá - I have everything I needed in the work notes written like:
Option 1: false
Option 2: true
Option 3: true
Needed a bit of thinking but it worked out smoothly.
Maybe this may help other people struggling with it in the future.
Best regards
Elena