GlideappVariablePoolQuestionSet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 05:13 AM
Hi,
I have notification script in place but i want list collector values to be in diffrent line rather than to appear in the same line in comma seperated fashion. So, i want to know if i can get the type of variable using GlideappVariablePoolQuestionSet in email script? if you have any alternative pls suggest.
Thanks,
Pankaj Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 10:29 PM
Yes, you can get the type of variable using GlideappVariablePoolQuestionSet in an email script. Here are the steps:
1. Create an instance of GlideappVariablePoolQuestionSet.
2. Use the get() method to get the variable.
3. Use the getDisplayValue() method to get the display value of the variable.
4. Use the getType() method to get the type of the variable.
Here is a sample code:
javascript
var glideVarPool = new GlideappVariablePoolQuestionSet();
glideVarPool.get(current);
var variables = glideVarPool.getFlatQuestions();
for (var i = 0; i < variables.size(); i++) {
var variable = variables.get(i);
var displayValue = variable.getDisplayValue();
var type = variable.getType();
gs.info('Variable: ' + displayValue + ', Type: ' + type);
}
In this code:
- current is the current record.
- glideVarPool.get(current) gets the variables for the current record.
- glideVarPool.getFlatQuestions() gets a list of all the variables.
- variable.getDisplayValue() gets the display value of the variable.
- variable.getType() gets the type of the variable.
To make list collector values appear in different lines rather than in a comma-separated fashion, you can use the split() method to split the values at the comma and then join them with a newline character. Here is a sample code:
javascript
var listCollectorValues = variable.getDisplayValue();
var valuesInDifferentLines = listCollectorValues.split(',').join('\n');
gs.info('Values in different lines: ' + valuesInDifferentLines);
In this code:
- variable.getDisplayValue() gets the display value of the list collector variable, which is a comma-separated string.
- listCollectorValues.split(',') splits the string at the comma, resulting in an array of values.
- valuesInDifferentLines.join('\n') joins the array of values with a newline character, resulting in a string where each value is on a different line.
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - nowgpt.ai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 11:22 PM
Hi @Pankaj kr
You can run below script in background (Change the sys_id of ritm as per your instance)-
This script can be modified as well for mail script.
Sample Script:
var gr=new GlideRecord('sc_req_item');
gr.get('a183fa5a47bbbd10569f962f316d4316');//change this as per your instance record
var variables = gr.variables.getElements(false);
for(var i=0;i<variables.length;i++)
{
var variable=variables[i];
var lbl=variable.getQuestion().getLabel();
var disVal=variable.getQuestion().getDisplayValue();
var var_type=variable.getQuestion().getType();//21=List Collector, 33=Attachments
if(var_type==33)
continue;
if(disVal)
{
if(var_type==21)//for list collector
{
gs.info("(List Collector) "+lbl+":");//if it is in mail script = template.print() instead of gs.info()
for(var j=0;j<disVal.split(",").length;j++)
{
gs.info((j+1)+". "+disVal.split(",")[j].trim())//if it is in mail script = template.print() instead of gs.info()
}
}
else
gs.info(variable.getQuestion().getLabel()+": "+(variable.getQuestion().getDisplayValue()))//if it is in mail script = template.print() instead of gs.info()
}
}
C |
If the provided solution meets your needs, kindly consider marking it as helpful and accepting it as the solution. This helps others who may have similar questions. |
Thanks and Regards,
Saurabh Gupta