- 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
‎05-17-2017 01:17 AM
Hello Humble, Christopher,
I need some help here. I have some similar scenario. I have 4 catalog item checkbox variables.
I wanted to print whichever checkbox are true, it should print in the email notification.
I am writing an email script in the "sysapproval_approver" table.
But inside the email notification it is not printing the checkbox names that are selected/true.
Here is my email script code below:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
template.print("");
var fStr = 'current.document_id.variables.CER_addDev,current.document_id.variables.CER_addPre,current.document_id.variables.CER_addTest,current.document_id.variables.CER_addUat';
var fArray = fStr.split(',');
for (i = 0; i < fArray.length; i++) {
if(current[fArray[i]]) {
var label = current[fArray[i]].getLabel() + ',';
template.print(label);
}
}
})(current, template, email, email_action, event);
Kindly help me achieve my requirement in urgent priority.
Regards,
Narayan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2017 08:01 AM
Variables are stored within an object on the record to be approved. We will need to iterate through all of the variables and check to see if the variable is one we want to check. Since variable checkbox values are stored as strings, we will need to do a check against the string value of 'true'.
I see you are trying to use the document_id field. We will have more success if we use the hidden sysapproval field as this is an actual reference field and will allow us to more easily get at the variables object. Based upon your original script, I modified it to use the above method:
var vString = 'CER_addDev,CER_addPre,CER_addTest,CER_addUat';
for (key in current.sysapproval.variables) {
var v = current.sysapproval.variables[key];
var vName = v.getGlideObject().getQuestion().getName().toString();
if (vString.indexOf(vName) > -1) {
vValue = v.getGlideObject().getQuestion().getDisplayValue();
if (vValue == 'true') {
template.print(v.getGlideObject().getQuestion().getLabel());
}
}
}
Let me know if you need further explanation of what is going on in the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2017 12:06 AM
Hello Christopher,
Thanks a lot for the help.
I have used the script which you have referred. However, I am still having an issue.
This is the email script which I am using. Please refer to the screenshot:
And this is the below output which I am getting. Kindly note I am getting the display value of "Risk_earth_quake" checkbox in the lower block as well. That should be available in the upper block only if it is checked.
Let me know, what needs to be done in this case.
Warm Regards,
Narayan Saha

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2017 06:51 AM
According to your code you are checking against a Risk_earth_quake2 variable as well as a variable called Risk_earth_quake. The indexOf method will find the portion of the name Risk_earth_quake as well as Risk_earth_quake2 because Risk_earth_quake is contained within Risk_earth_quake2. Here is a simple piece of code you can run in Scripts - Background that proves this:
var vName = 'var_name';
//var vName = 'var_name2';
var vString = 'var_name2,var_something';
if (vString.indexOf(vName) > -1) {
gs.print('found it');
}
Probably the best thing to do is to rename Risk_earth_quake to be Risk_earth_quake1, or even rename Risk_earth_quake2 to be risk_earth_quake2 because the indexOf method is case sensitive.