- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2017 04:33 AM
I have a script that seems to be working fine, but I need to tidy it up a bit.
For the moment the business rule copied the variables on the requested item to the comments [work-notes]
But as you can see its not very tidy. Is there a way to get only the variables the customer selected to show rather than all the variables on the form?
Variables:
Who requires assistance?: Mitch Sharpe
Member Firm: NRFLLP
Location: London
Are you raising this request to Add or Remove access? : Add
What is your access start date: 15/Nov/2017 11:05:34
What is your access end date?:
What is your access end date?:
NRF: false
GSC: true
Are you raising this request for HR or Finance?: Finance
HR Action & HR Ad Hoc: false
Adhoc Finance Requests for GSC: false
Fixed Asset Registration: true
Time Amendment: false
Vendor Requests: false
Which User Groups in the Adhoc Finance Requests for GSC Workflow do you need to add or remove access to?:
Which User Groups in the Adhoc Finance Requests for GSC Workflow do you need to add or remove access to?:
Which User Groups in the Fixed Asset Registration for NRF Workflow do you need to add or remove access to? :
Which User Groups in the Fixed Asset Registration for GSC Workflow do you need to add or remove access to? : EMEA_PTP_FA_TECHNICIAN
Which User Groups in the HR Action & HR Ad Hoc NRF Workflow do you need to add or remove access to? :
Which User Groups in the HR Action & HR Ad Hoc GSC Workflow do you need to add or remove access to? :
Which User Groups in the Time Amendment GSC Workflow do you need to add or remove access to? :
Which User Groups in the Time Amendment NRF Workflow do you need to add or remove access to? :
Which User Groups in the Vendor Requests NRF Workflow do you need to add or remove access to? :
Which User Groups in the Vendor Requests GSC Workflow do you need to add or remove access to? :
If you have any additional comments or information, please fill them in here.:
Current script is
(function executeRule(current, previous /*null when async*/) {
// Add your code here.
var wn = 'Variables:';
for (key in current.variables) {
var v = current.variables[key];
wn += '\n' + v.getGlideObject().getQuestion().getLabel() + ': ' + v.getDisplayValue();
}
current.comments = wn;
})(current, previous);
Kind regards
Sarah
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2017 05:16 AM
Try the below code. I am setting it to description. It pulls only filled variables
toDescription();
function toDescription() {
var notEmptyVars = [];
var v;
var desc = '';
/* Put all variable values and labels from the variable pool into an array */
for (var i in current.variables) {
v = current.variables[i];
/* Only include non-empty variables, and exclude Label and Container variables */
if (v != '' && v != 'false' && v.getGlideObject().getQuestion().type != 11 && v.getGlideObject().getQuestion().type != 19 && v.getGlideObject().getQuestion().type != 20) {
desc += v.getGlideObject().getQuestion().getLabel() + ': ' + v.getDisplayValue() + '\n';
}
}
current.description = desc;
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 01:59 AM
Hi,
Have you found another solution for this? Same issue with not working in Madrid.
Best regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2019 12:51 PM
Hi there, here is the updated code I have written in Madrid and tested, works great.
(function executeRule(current, previous /*null when async*/) {
var v;
var worknotes = '';
var variables = current.variables.getElements();
for (var i in variables) {
v = variables[i];
if (v.getQuestion().type != 11 && v.getQuestion().type != 19 && v.getQuestion().type != 20 && v.getDisplayValue() != '') {
worknotes += v.getQuestion().getLabel() + ": " + v.getDisplayValue() + "\n";
}
}
current.work_notes = worknotes;
})(current, previous);