- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2015 08:06 PM
Hello everyone,
I have a record producer with some variables, let say for example url1, url2, url3 type single text, I need to capture the values of these variables(This is the hard part) for a further work. I've tried using producer.variable1, and as planned get the value of the variable , but I need to get all of them using a loop or something similar, I tried to access the producer object but didn't work
var sitesArray = [];
for(var v in producer){
if(v.indexOf('url') > -1){
var temp = '';
if( (v.indexOf('url') > -1) && (current.variables[v] != '') ){
temp = v.substring(3);
if(sitesArray[temp] == null || sitesArray[temp] == undefined){
sitesArray[temp] = [];
}
sitesArray[temp]['url'] = current.variables[v];
}
}
But seems to not work, if you guys have any suggestions please let me know.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2015 12:02 PM
Hello Guillermo,
I played around with a the Create Incident record producer in my personal instance. The variables are included in the producer object and their key starts with the letters "IO" followed by their sys_id. I'm not sure if there is a better/easier way to get the question text than using a GlideRecord query.
This script put the key value pair of all variables in the work_notes for me in my test:
var test = [];
for(var v in producer){
if (v.startsWith("IO")) { //only variables
var question = new GlideRecord('item_option_new');
question.get(v.substring(2)); // Querying by sys_id to determine question text
test += question.question_text + ": " + producer[v] + "\n"; // Set key:value pair to variable
}
}
current.work_notes = test; // Set Work Notes on new record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2018 03:49 AM
Hi Guillermo,
It is working fine only thing is they are not in the order how they have submitted in the front end.
How to sort it based on the variables order?
Thanks & Regards,
Ram Prakash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2018 08:58 AM
Hello,
I have updated this script since it was posted to use an encoded query so that it respects the variable order:
current.description = createDescription();
function createDescription() {
var description = '',
rpVarIDs = [];
for (var v in producer) {
if (v.startsWith("IO")) { // Only Questions
// Collect Sys IDs of Questions
rpVarIDs.push(v.substring(2));
}
}
var question = new GlideRecord('item_option_new');
question.addEncodedQuery('sys_idIN' + rpVarIDs.join() + '^ORDERBYorder');
question.query();
while (question.next()) {
var propName = "IO" + question.sys_id.toString();
if (producer[propName]) {
description += question.question_text + ": " + producer[propName].getDisplayValue() + "\n"; // Set key:value pair to variable
}
}
return description;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2021 08:17 AM
question.addEndodedQuery('sys_id' +rpVARIDs.join() + '^ORDERBYorder');
can you please explain this line in simple way?
Need to know what happens over there
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 04:46 AM
Hi,
Is there a way to get the display value of a selectbox variable?
Tried using below with no luck. Thank you
producer[propName].getDisplayValue()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2021 06:10 AM
Were do we need add this script and on what table,is it a BR or Script include ?