- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2021 03:48 AM
I am trying to auto populate the short description field on the requeted item table using information from variables submitted via the service portal. This is being done using the business rule below
"(function executeRule(current, previous /*null when async*/) {
//On before insert business rule
//Condition where item contains Onboarding
//Updates the short description with concatenated variables
current.short_description = current.variables.var_company.getDisplayValue() + ' ' + 'Onboarding' + ' / ' + current.variables.var_full_name + ' / ' + current.variables.var_start_date +' / ' + current.cat_item.getDisplayValue();
})(current, previous);
"
The rule works well except tha the date time variable (var_start_date) is being displayed in the wrong format. Our business have asked if the format can be changed to be "DD-MM-YYYY" rather than the default "MM-DD-YYYY"
Is it possible to this within the business rule?
Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2021 04:03 AM
yes you can convert that
update as this and let us know.
(function executeRule(current, previous /*null when async*/) {
var startDate = current.variables.var_start_date;
var gdt = new GlideDateTime();
var format = 'MM-dd-YYYY HH:mm:ss';
gdt.setDisplayValue(startDate + ' 23:59:59');
var dt = new GlideDate();
dt.setValue(gdt.getDate());
var myFormattedStartValue = dt.getByFormat('dd-MM-YYY');
current.short_description = current.variables.var_company.getDisplayValue() + ' ' + 'Onboarding' + ' / ' + current.variables.var_full_name + ' / ' + myFormattedStartValue +' / ' + current.cat_item.getDisplayValue();
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2023 12:40 PM - edited ‎04-21-2023 12:41 PM
Ankur,
Thanks for the script. I modified what you provided and it's working perfect. I needed a date format of 'MM-dd-YYYY'. Below is my modified script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
// added by MCD 4.13.23
var tedDate = current.variables.transfer_effective_date;
var gdt = new GlideDateTime();
var format = 'YYYY-MM-dd';
gdt.setDisplayValue(tedDate);
var dt = new GlideDate();
dt.setValue(gdt.getDate());
var myFormattedValue = dt.getByFormat('MM-dd-YYYY');
current.short_description = "Transfer - " + current.variables.full_name + ' - ' + '\n' + myFormattedValue;
})(current, previous);
Thanks.
Mike