How do I combine record producer variable fields into one comment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 12:38 PM
I have the following script for a record producer.
if (producer.url == "")
current.comments = " ";
else
current.comments = "URL in question: " + '\n' + producer.url;
if (producer.loaner_laptop == "")
current.comments = " ";
else
current.comments = "Loaner Laptop reservation requested: " + '\n' + producer.loaner_laptop.getDisplayValue();
It creates two comments for the incident.
How do I makes these into one with separation of values on different lines?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 12:52 PM
Hello,
Can you attempt to attach your screenshot again? It doesn't appear to be visible.
To your question though, are you trying to combine both the URL and Loaner comments into one?
Please mark my answer as correct/helpful if it has helped you.
Thanks,
Logan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 12:55 PM
What you might want to do is create a variable to store all of the values, then push the contents of the variable into the comments field:
var comString;
if (producer.url == ""){
current.comments = " ";
} else {
comString = "URL in question: " + '\n' + producer.url;
if (producer.loaner_laptop == "") {
comString = " ";
} else {
comString = "Loaner Laptop reservation requested: " + '\n' + producer.loaner_laptop.getDisplayValue();
}
current.comments = comString;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 01:02 PM
I was thinking the same -- javascript arrays and the .join() function are useful for doing this with less lines of code:
var msgs = [];
if (producer.getValue('url')) {
msgs.push('URL in question: \n' + producer.getValue('url'));
}
if (producer.getValue('loaner_laptop')) {
msgs.push('Loaner Laptop reservation requested: \n' + producer.getDisplayValue('loaner_laptop'));
}
current.setValue('comments', msgs.join('\n\n'));
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry
