- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 04:04 AM
Following up on discussion in Thread: Copy variable details to RITM description
We've applied Ankur's solution in a Business Rule to fetch Variable Values from new RP records ("Cases" for us) and populate a new String field "Case Variable Summary", see below:
var variables = current.variables.getElements();
var str = '';
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var variableLabel = question.getLabel();
var variableValue = question.getDisplayValue();
str = str + variableLabel + ' - ' + variableValue + '\n';
}
current.case_variable_summary = str;
What we need to do is to apply this logic to existing records so we can backfill the new field "case_variable_summary" in each Case we have logged.
We started down the road of GlideRecord:
var gd = new GlideRecord('case');
var a = gd.addNullQuery('case_variable_summary');
a.addCondition('active','true');
gd.query();
while(gd.next())
{
// this is where we need the BR Logic
}
But it's proved fruitless so far. Can you help?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 04:45 AM
We got there...
var gd = new GlideRecord('case');
var a = gd.addNullQuery('case_variable_summary');
a.addCondition('active','true');
gd.query();
while(gd.next())
{
var varSum = gd.variables.getElements();
var str = '';
for (var i=0;i<varSum.length;i++) {
var question = varSum[i].getQuestion();
var variableLabel = question.getLabel();
var variableValue = question.getDisplayValue();
str = str + variableLabel + ' - ' + variableValue + '\n';
}
gd.case_variable_summary = str;
gd.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 04:38 AM
Update, we're getting somewhere...
var gd = new GlideRecord('case');
var a = gd.addNullQuery('case_variable_summary');
a.addCondition('active','true');
gd.setLimit(5); // Set value for testing purposes only
gd.query();
while(gd.next())
{
var varSum = gd.variables.getElements();
var str = '';
for (var i=0;i<varSum.length;i++) {
var question = varSum[i].getQuestion();
var variableLabel = question.getLabel();
var variableValue = question.getDisplayValue();
str = str + variableLabel + ' - ' + variableValue + '\n';
}
gs.info(gd.number + " - " + str); // This returns the variable values and the RP Number in one field.
}
We just need to have the return value update the case_variable_summary field. So watch this space... 😄
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 04:45 AM
We got there...
var gd = new GlideRecord('case');
var a = gd.addNullQuery('case_variable_summary');
a.addCondition('active','true');
gd.query();
while(gd.next())
{
var varSum = gd.variables.getElements();
var str = '';
for (var i=0;i<varSum.length;i++) {
var question = varSum[i].getQuestion();
var variableLabel = question.getLabel();
var variableValue = question.getDisplayValue();
str = str + variableLabel + ' - ' + variableValue + '\n';
}
gd.case_variable_summary = str;
gd.update();
}