
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 02:44 PM - edited 06-04-2024 02:44 PM
I have a catalog item that shows instructions in HTML based on an on change script and three different scripted notifications with just the intro changed based on the circumstances (next steps, reminder and renewal). The notifications are either kicked off by record changes or scheduled jobs/events. This means whenever I need to change the instructions (which the business unit does often), I have to change it in multiple spots. I'm wondering if there is a way to write the code so it can be called into a catalog html field and the 3 different types of notifications. Could this be done in a script include? Is there some way I could allow the business to change the verbiage on demand without using a custom table (my senior engineer won't approve a new table)?
I'm just trying to reduce dev effort on these constant changes.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 03:20 PM
Hi @litchick10 ,
You need to have the below four components-
Script Include: for the instruction logic.
Client Script: to fetch and display instructions in catalog items.
Notification Script: to embed instructions in notifications.
System Properties: Allows users to update instructions. (Optional) So that we don't need to change the code and update the properties instead.
You should create a script include that can be called multiple times-
Script includes-
var InstructionHelper = Class.create();
InstructionHelper.prototype = {
initialize: function() {
},
getInstructions: function(type) {
var instructions = "";
switch(type) {
case 'next_steps':
instructions = gs.getProperty('instruction.next_steps', 'Default next steps instructions');
break;
case 'reminder':
instructions = gs.getProperty('instruction.reminder', 'Default reminder instructions');
break;
case 'renewal':
instructions = gs.getProperty('instruction.renewal', 'Default renewal instructions');
break;
default:
instructions = 'Default instructions...';
}
return instructions;
},
type: 'InstructionHelper'
};
Client Script-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('InstructionHelper');
ga.addParam('sysparm_name', 'getInstructions');
ga.addParam('sysparm_type', 'next_steps'); // Change the type as needed
ga.getXMLAnswer(function(response) {
var instructions = response;
g_form.setValue('instruction_field', instructions); // Set the value of your HTML field
});
}
Notification Script-
(function() {
var helper = new InstructionHelper();
var instructions = helper.getInstructions('reminder'); // Change the type as needed
template.print(instructions);
})();
Lastly create the system properties-
for each type of instruction, e.g., instruction.next_steps, instruction.reminder, instruction.renewal
Update the above as per your requirement.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 03:20 PM
Hi @litchick10 ,
You need to have the below four components-
Script Include: for the instruction logic.
Client Script: to fetch and display instructions in catalog items.
Notification Script: to embed instructions in notifications.
System Properties: Allows users to update instructions. (Optional) So that we don't need to change the code and update the properties instead.
You should create a script include that can be called multiple times-
Script includes-
var InstructionHelper = Class.create();
InstructionHelper.prototype = {
initialize: function() {
},
getInstructions: function(type) {
var instructions = "";
switch(type) {
case 'next_steps':
instructions = gs.getProperty('instruction.next_steps', 'Default next steps instructions');
break;
case 'reminder':
instructions = gs.getProperty('instruction.reminder', 'Default reminder instructions');
break;
case 'renewal':
instructions = gs.getProperty('instruction.renewal', 'Default renewal instructions');
break;
default:
instructions = 'Default instructions...';
}
return instructions;
},
type: 'InstructionHelper'
};
Client Script-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('InstructionHelper');
ga.addParam('sysparm_name', 'getInstructions');
ga.addParam('sysparm_type', 'next_steps'); // Change the type as needed
ga.getXMLAnswer(function(response) {
var instructions = response;
g_form.setValue('instruction_field', instructions); // Set the value of your HTML field
});
}
Notification Script-
(function() {
var helper = new InstructionHelper();
var instructions = helper.getInstructions('reminder'); // Change the type as needed
template.print(instructions);
})();
Lastly create the system properties-
for each type of instruction, e.g., instruction.next_steps, instruction.reminder, instruction.renewal
Update the above as per your requirement.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2024 11:33 AM
How do I do the notification script if I have two parameters (n_type = 'reminder', sysID = [record sys id])

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 08:55 AM
Thanks so much, this was where my mind was going with this as well, the system properties is something I didn't think of. Appreciate your guidance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 09:22 AM
Hi @litchick10 ,
You are welcome, using system properties makes configuration that require data that need to change.
Wherever you are hardcoding some values try using system properties.
Thanks,
Sanjay Kumar