- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2021 11:48 AM
Hello Community,
I need your help. Saving the backstory i need to do what i feel should be simple but for whatever reason i am unable to use my knowledge to be successful.
I have a working email script that is working, but i have (12) copies of this code in the script and i know i can reduce this down to one occurance in which it can interate through an array and only have one piece of code.
*****
if (current.variables.ldap != 'Yes') {
template.print("<br/><br/>" + current.variables.ldap.getGlideObject().getQuestion().getLabel() + ": <b>" +
current.variables.ldap.getGlideObject().getQuestion().getValue() +
"</b><br/> Implemented at go-live?: <b>" +
current.variables.ldap_go_live.getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
current.variables.ldap_reason.getGlideObject().getQuestion().getValue())+"</b>";
} else {
template.print("<br/><br/>" + current.variables.ldap.getGlideObject().getQuestion().getLabel() + ": <b>" +
current.variables.ldap.getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
current.variables.ldap_reason.getGlideObject().getQuestion().getValue())+"</b>";
}
*****
What im trying to do is this...
var VARIABLE = ['ldap','fsso']; //<<<will be all 12 names in the list<<<
for( var i = 0; i < myArray.length; i ++){
var qna = myArray [i];
if (current.variables.[VARIABLE] != 'Yes') {
template.print("<br/><br/>" + current.variables.[VARIABLE].getGlideObject().getQuestion().getLabel() + ": <b>" +
current.variables.[VARIABLE].getGlideObject().getQuestion().getValue() +
"</b><br/> Implemented at go-live?: <b>" +
current.variables.[VARIABLE]_go_live.getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
current.variables.[VARIABLE]_reason.getGlideObject().getQuestion().getValue())+"</b>";
} else {
template.print("<br/><br/>" + current.variables.[VARIABLE].getGlideObject().getQuestion().getLabel() + ": <b>" +
current.variables.[VARIABLE].getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
current.variables.[VARIABLE]_reason.getGlideObject().getQuestion().getValue())+"</b>";
}
break;
}
Anyone that can help me I would be greatly appreciative.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2021 10:17 AM
Spencer,
Sounds good; I think the issue is with resolving the dot walk and string combinations. I concatenated the string to hopefully solve this and attached a rough draft of the current script. First, we should ensure the variableName and variableVaule are correct before moving to this full script.
(function runMailScript(current, template, email, email_action, event) {
var list = 'ldap,fsso,data_at_rest,tls,endpoint,patch30,network,seperation,us_data,logging,risk_asmt,pentest';
var array = list.split(",");
for (var i = 0; i < array.length; i++) {
var VariableName = current.variables + "." + array[i];
gs.log('VariableName');
var VariableValue = VariableName.getValue();
gs.log('VariableValue')
if (VariableValue != 'Yes') {
template.print(VariableName + "." + getGlideObject().getQuestion().getLabel() + ": <b>" +
VariableName + "." + getGlideObject().getQuestion().getValue() +
"</b><br/> Implemented at go-live?: <b>" +
VariableName + "_go_live." + getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
VariableName + "_reason." + getGlideObject().getQuestion().getValue() + "</b>");
} else {
template.print("OR HERE<br/><br/>" + VariableName + "."+ getGlideObject().getQuestion().getLabel() + ": <b>" +
VariableName + "." + getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
VariableName + "_reason." + getGlideObject().getQuestion().getValue() + "</b>");
}
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2021 12:16 PM
Spencer,
You can try something like this but I have not tested it:
var list = 'ldap,fsso,xyz';
var array = list.split(",");
for (var i = 0; i < array.length; i++) {
var VariableValue = current.variables.array[i]
if (current.variables.array[i] != 'Yes') {
template.print("<br/><br/>" + VariableValue.getGlideObject().getQuestion().getLabel() + ": <b>" +
VariableValue.getGlideObject().getQuestion().getValue() +
"</b><br/> Implemented at go-live?: <b>" +
VariableValue + _go_live.getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
VariableValue + _reason.getGlideObject().getQuestion().getValue())+"</b>";
} else {
template.print("<br/><br/>" + VariableValue.getGlideObject().getQuestion().getLabel() + ": <b>" +
VariableValue.getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
VariableValue + _reason.getGlideObject().getQuestion().getValue())+"</b>";
}
}
Thanks,
Derrick Johnson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2021 03:37 AM
@djohnson
looking at this I know it should work but for some reason I the array is coming up "Cannot read property "0" from undefined" when I run it. Added gs.log all over the place and we are seeing that it appears there is a problem with array.
any thoughts would be appreciated
--- extract from log ---
syslog.message=org.mozilla.javascript.EcmaError: Cannot read property "0" from undefined
Caused by error in Email Script: 'rp_mssa_email_script' at line 9
6: gs.log("sra mssa split");
7: for (var i = 0; i < array.length; i++) {
8: gs.log("sra mssa valusset" + array.length[i]);
==> 9: var VariableValue = current.variables.array[i];
10: gs.log("sra array: " + current.variables.array[i]);
11: if (current.variables.array[i] != 'Yes') {
--- entire script (less the gs.log entries and random troubleshooting text)---
(function runMailScript(current, template, email, email_action, event) {
var list = 'ldap,fsso,data_at_rest,tls,endpoint,patch30,network,seperation,us_data,logging,risk_asmt,pentest';
var array = list.split(",");
for (var i = 0; i < array.length; i++) {
var VariableValue = current.variables.array[i];
if (current.variables.array[i] != 'Yes') {
template.print(VariableValue.getGlideObject().getQuestion().getLabel() + ": <b>" +
VariableValue.getGlideObject().getQuestion().getValue() +
"</b><br/> Implemented at go-live?: <b>" +
VariableValue + "_go_live." + getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
VariableValue + "_reason." + getGlideObject().getQuestion().getValue() + "</b>");
} else {
template.print("OR HERE<br/><br/>" + VariableValue.getGlideObject().getQuestion().getLabel() + ": <b>" +
VariableValue.getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
VariableValue + "_reason." + getGlideObject().getQuestion().getValue() + "</b>");
}
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2021 07:32 AM
Spencer,
I noticed the issue was with the varibalevalue, I've modified the script and added some logs. Can you try this and if it doesn't work send me the log statements.
(function runMailScript(current, template, email, email_action, event) {
var list = 'ldap,fsso,data_at_rest,tls,endpoint,patch30,network,seperation,us_data,logging,risk_asmt,pentest';
var array = list.split(",");
for (var i = 0; i < array.length; i++) {
var VariableName = current.variables + "." + array[i];
gs.log('VariableName');
var VariableValue = VariableName.getValue();
gs.log('VaribaleValue')
if (VariableValue != 'Yes') {
template.print(VariableName.getGlideObject().getQuestion().getLabel() + ": <b>" +
VariableName.getGlideObject().getQuestion().getValue() +
"</b><br/> Implemented at go-live?: <b>" +
VariableName + "_go_live." + getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
VariableName + "_reason." + getGlideObject().getQuestion().getValue() + "</b>");
} else {
template.print("OR HERE<br/><br/>" + VariableName.getGlideObject().getQuestion().getLabel() + ": <b>" +
VariableName.getGlideObject().getQuestion().getValue() +
"</b><br/> Additional details/Comments: <b>" +
VariableName + "_reason." + getGlideObject().getQuestion().getValue() + "</b>");
}
}
})(current, template, email, email_action, event);
Thanks,
Derrick Johnson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2021 08:35 AM
will do.
let you know soon