- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2016 06:09 PM
Hello community,
I have Change Requests and Service Requests (really any template that has True/False check boxes) that I need to populate or print out on email templates when they are "checked marked" or marked True.
Here are the fields on the Change Request:
Here are their respected variable element names in xml format:
<u_stx01>false</u_stx01>
<u_stx02>false</u_stx02>
<u_sys01>false</u_sys01>
<u_tim01>false</u_tim01>
<u_trn01>false</u_trn01>
<u_uat01>false</u_uat01>
<u_statehub>false</u_statehub>
<u_stg01>false</u_stg01>
<u_oem___monitoring>false</u_oem___monitoring>
<u_prd01>false</u_prd01>
<u_psd02>false</u_psd02>
<u_kolea>false</u_kolea>
<u_int01>false</u_int01>
<u_dev01>false</u_dev01>
<u_dev03>false</u_dev03>
<u_drx01>false</u_drx01>
<u_ecm>false</u_ecm>
I am assuming there is some sort of ${email_script:} that I would need to create to run some type of query to pull the labels of all the ones that are "true" and include that in the email template body but not sure how to capture that. Maybe print them out in an array of elements that are true?
Any and all help is greatly appreciated. Thanks in advanced.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2016 02:33 PM
The more I look at what you have, it appears as if these are actual fields and not Variables so my solution would not be truly applicable.
Probably the best way would be to write a repeatable method for checking a field. You can actually pull together an array of fields and process each by surrounding the field name in brackets. Using your environments checkboxes as an example:
template.print('<p>Impact:<br />');
var fStr ='u_stx01,u_stx02,u_sys01,u_tim01,u_trn01,u_uat01,u_statehub,u_stg01,u_oem___monitoring'
var fArray = fStr.split(',');
for (i = 0; i < fArray.length; i++) {
if(!current[fArray[i]]) {
var label = current[fArray[i]].getLabel() + '<br />';
template.print(label);
}
}
template.print('</p>');
Since true/false values can be evaluated by pointing to the field itself, we just use the field in the evaluation. Typically we are doing a current.field_name combination, but since we are evaluating a slice of an array, we replace the dot accordingly: current[fArray[i]]
We also do the same with getting the label of the field using the getLabel() method: current[fArray[i]].getLabel()
This should get you started in writing a more concise script that will give you the Labels of the fields if they are true.
As for the Environment 1 and Environment 2 fields, you should be able to do a similar evaluation:
template.print('<p>Environment Tiers:<br />');
var fStr2 ='u_environment1,u_environment2'
var fArr2 = fStr.split(',');
for (x = 0; x < fArr2.length; x++) {
if(current[fArr2[x]] != '') {
var label = current[fArr2[x]].getLabel() + '<br />';
template.print(label);
}
}
template.print('</p>');
Let me know if you have any questions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2016 11:54 AM
Unfortunately because the variables for Record Producers live on a different table, the functions that are used for Catalog Request do not apply. I have created a Script Include that does all the heavy lifting for parsing the variables that can be called from a mail_script. Let me know if you are interested and I can supply what I have as a starting point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2016 12:18 PM
Hello Christopher,
Any code would greatly be appreciated as it may provide a method that I over looked or a logic I never even considered.
So far, a lengthy work around that I am working with is the following.
template.print("Impact:<br />");
template.print("Environments:<br /> " + ": " + "<br />");
if ("${u_kolea}" == 'true'){
template.print("KOLEA " + "\n");
}
if ("${u_statehub}" == 'true'){
template.print("STATEHUB " + "\n");
}
if ("${u_ecm}" == 'true'){
template.print("ECM " + "\n");
}
template.print("KOLEA <br />" + "\n");
template.print("STATEHUB <br />" + "\n");
template.print("ECM <br />" + "\n");
template.print("<br />"); // if the true/false statement is true then print out the variable name in the body of the email via script.
/////////////////////////////////////////////////////////////////////
template.print("Environments Tiers " + ": " + "<br />");
template.print("${u_environment1} <br />" + " ${u_environment2} <br />"); //another method is to print drop down menus, it will only print if it is a value other than "--none--"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2016 02:33 PM
The more I look at what you have, it appears as if these are actual fields and not Variables so my solution would not be truly applicable.
Probably the best way would be to write a repeatable method for checking a field. You can actually pull together an array of fields and process each by surrounding the field name in brackets. Using your environments checkboxes as an example:
template.print('<p>Impact:<br />');
var fStr ='u_stx01,u_stx02,u_sys01,u_tim01,u_trn01,u_uat01,u_statehub,u_stg01,u_oem___monitoring'
var fArray = fStr.split(',');
for (i = 0; i < fArray.length; i++) {
if(!current[fArray[i]]) {
var label = current[fArray[i]].getLabel() + '<br />';
template.print(label);
}
}
template.print('</p>');
Since true/false values can be evaluated by pointing to the field itself, we just use the field in the evaluation. Typically we are doing a current.field_name combination, but since we are evaluating a slice of an array, we replace the dot accordingly: current[fArray[i]]
We also do the same with getting the label of the field using the getLabel() method: current[fArray[i]].getLabel()
This should get you started in writing a more concise script that will give you the Labels of the fields if they are true.
As for the Environment 1 and Environment 2 fields, you should be able to do a similar evaluation:
template.print('<p>Environment Tiers:<br />');
var fStr2 ='u_environment1,u_environment2'
var fArr2 = fStr.split(',');
for (x = 0; x < fArr2.length; x++) {
if(current[fArr2[x]] != '') {
var label = current[fArr2[x]].getLabel() + '<br />';
template.print(label);
}
}
template.print('</p>');
Let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2016 03:09 PM
Christopher,
I just want to let you know how much appreciation I have with the amount of support you are supplying the community and myself with answering this question.
The amount of explanation to the coding is beautiful, and thank you for that level of detail!
I am playing around with your array and for some reason it is only printing the u_oem___monitoring field (which is marked as false and not sure if the "!" has anything to do with it) while the others are all marked as true and is not being printed.
I am trying to go through it now and will let you know if I find out what is preventing the code to work. If you have any tips please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2016 03:13 PM
Hello Christopher,
I have detected my error.
It was in reference to what field names I listed in the Array and now things are working beautifully. You are a guru sir!
Here is the final code:
template.print("Impact:<br />");
template.print("Environments:<br /> ");
template.print('<p>Impact:<br />');
var fStr ='u_kolea,u_statehub,u_ecm,u_oem___monitoring';
var fArray = fStr.split(',');
for (i = 0; i < fArray.length; i++) {
if(current[fArray[i]]) {
var label = current[fArray[i]].getLabel() + '<br />';
template.print(label);
}
}
template.print('</p>');
/////////////////////////////////////////////////////////////////////
template.print("Environments Tiers " + ": " + "<br />");
var fStr ='u_prd01,u_dev01,u_dev03,u_drx01,u_int01,u_psd02,u_stg01,u_stx01,u_stx02,u_sys01,u_tim01,u_trn01,u_uat01';
var fArray = fStr.split(',');
for (i = 0; i < fArray.length; i++) {
if(current[fArray[i]]) {
var label = current[fArray[i]].getLabel() + '<br />';
template.print(label);
}
}
template.print('</p>');
And now it works perfectly when check marked fields are selected.
The following screen shots are the true/false fields that were selected in the Change Request, and thus printed to the email.
Thanks again Christopher et al, you guys rock!