- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2017 12:01 PM
I'm working on a Catalog Item that allows users to request access to 1-20 databases. I defined variables for each of the databases and change which are displayed based on how many the user requested. I get the variables to display properly in the RITM but need the Workflow to be able to publish the variables to Approval Requests and Tasks in a way that will not show all variables for all 20 if only 1 database access was requested. I've successfully been able to get Some of the variables to publish to the Activities field, but it doesn't appear to be running the script properly. Can someone point out where my code is off and showing too many of the variables and often in the wrong order?
current.approval = 'requested';
var intDatabases = 1;
var x;
var grRequest = new GlideRecord('sc_req_item');
grRequest.get(current.sys_id);
if (grRequest.variables['numDatabases1'].getGlideObject().getValue() > 0 && grRequest.variables['numDatabases1'].getGlideObject().getValue() <= 20) {
intDatabases = current.variables.numDatabases1;
}
for (x = 1; x <= intDatabases; ++x) {
if (grRequest.variables['notListed' + x].getGlideObject().getBooleanAttribute()) {
grRequest.comments = "Database: " + grRequest.variables['txtDatabase' + x];
} else {
grRequest.comments = "Database: " + grRequest.variables['refDatabase' + x];
}
grRequest.comments += "\nTables: " + grRequest.variables['txtTables' + x];
grRequest.comments += "\nAccess Requested: ";
if (grRequest.variables['chkRead' + x].getGlideObject().getBooleanAttribute()) {
grRequest.comments += "Read";
if (grRequest.variables['chkWrite' + x].getGlideObject().getBooleanAttribute() || grRequest.variables['chkExecute' + x].getGlideObject().getBooleanAttribute()) {
if (grRequest.variables['chkWrite' +x].getGlideObject().getBooleanAttribute()) {
grRequest.comments += ", Write";
}
if (grRequest.variables['chkExecute' + x].getGlideObject().getBooleanAttribute()) {
grRequest.comments += ", Execute";
}
}
} else {
if (grRequest.variables['chkWrite' + x].getGlideObject().getBooleanAttribute()) {
grRequest.comments += "Write";
if (grRequest.variables['chkExecute' + x].getGlideObject().getBooleanAttribute()) {
grRequest.comments += ", Execute";
}
} else {
grRequest.comments += "Execute";
}
}
if (grRequest.variables['chkWrite' + x].getGlideObject().getBooleanAttribute()) {
grRequest.comments += "\nAltering Data: " + grRequest.variables['ynAlter' + x];
if (grRequest.variables['ynAlter' + x].getGlideObject().getValue() == 'Yes') {
grRequest.comments += "\nData Altered: " + grRequest.variables['txtDataAltered' + x] + "\nContains PII: " + grRequest.variables['ynPII' + x];
}
}
if (x < intDatabases) {
grRequest.comments += "\n";
}
}
grRequest.update();
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2017 07:20 AM
I was able to eventually figure it out what was wrong with my variable references (I also decided to add the details to the Description instead of the comments as it's a field the people processing the request can later modify if needed). You can call a variable by gr.variables.<VariableName> or by gr.variables[VariableName]. The second version allows you to define the variable name in a formula as I did in situations like grRequest.variables['txtDataAltered' + x]. The problem I had was I didn't need to add the .getGlideObject(), .getBooleanAttribute(), or .getValue() at the end of each. I've copied the script that works for me as an example below.
current.approval = 'requested';
var intDatabases = 1;
var x = 1;
var grRequest = new GlideRecord('sc_req_item');
grRequest.get(current.sys_id);
if (grRequest.variables['numDatabases1'] > 0 && grRequest.variables['numDatabases1'] <= 20) {
intDatabases = grRequest.variables['numDatabases1'];
}
for (x = 1; x <= intDatabases; ++x) {
if (grRequest.variables['notListed' + x] == 'true') {
grRequest.description += "Database: " + grRequest.variables['txtDatabase' + x];
} else {
grRequest.description += "Database: " + grRequest.variables['refDatabase' + x].getDisplayValue();
}
grRequest.description += "\n - Tables: " + grRequest.variables['txtTables' + x];
grRequest.description += "\n - Access Requested: ";
if (grRequest.variables['chkRead' + x] == 'true') {
grRequest.description += "Read";
if (grRequest.variables['chkWrite' + x] == 'true' || grRequest.variables['chkExecute' + x] == 'true') {
if (grRequest.variables['chkWrite' +x] == 'true') {
grRequest.description += ", Write";
}
if (grRequest.variables['chkExecute' + x] == 'true') {
grRequest.description += ", Execute";
}
}
} else {
if (grRequest.variables['chkWrite' + x] == 'true') {
grRequest.description += "Write";
if (grRequest.variables['chkExecute' + x] == 'true') {
grRequest.description += ", Execute";
}
} else {
grRequest.description += "Execute";
}
}
if (grRequest.variables['chkWrite' + x] == 'true') {
grRequest.description += "\n - Altering Data: " + grRequest.variables['ynAlter' + x];
if (grRequest.variables['ynAlter' + x] == 'Yes') {
grRequest.description += "\n - Data Altered: " + grRequest.variables['txtDataAltered' + x] +
"\n - Contains PII: " + grRequest.variables['ynPII' + x];
}
}
if (x < intDatabases) {
grRequest.description += "\n";
}
}
grRequest.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2017 07:20 AM
I was able to eventually figure it out what was wrong with my variable references (I also decided to add the details to the Description instead of the comments as it's a field the people processing the request can later modify if needed). You can call a variable by gr.variables.<VariableName> or by gr.variables[VariableName]. The second version allows you to define the variable name in a formula as I did in situations like grRequest.variables['txtDataAltered' + x]. The problem I had was I didn't need to add the .getGlideObject(), .getBooleanAttribute(), or .getValue() at the end of each. I've copied the script that works for me as an example below.
current.approval = 'requested';
var intDatabases = 1;
var x = 1;
var grRequest = new GlideRecord('sc_req_item');
grRequest.get(current.sys_id);
if (grRequest.variables['numDatabases1'] > 0 && grRequest.variables['numDatabases1'] <= 20) {
intDatabases = grRequest.variables['numDatabases1'];
}
for (x = 1; x <= intDatabases; ++x) {
if (grRequest.variables['notListed' + x] == 'true') {
grRequest.description += "Database: " + grRequest.variables['txtDatabase' + x];
} else {
grRequest.description += "Database: " + grRequest.variables['refDatabase' + x].getDisplayValue();
}
grRequest.description += "\n - Tables: " + grRequest.variables['txtTables' + x];
grRequest.description += "\n - Access Requested: ";
if (grRequest.variables['chkRead' + x] == 'true') {
grRequest.description += "Read";
if (grRequest.variables['chkWrite' + x] == 'true' || grRequest.variables['chkExecute' + x] == 'true') {
if (grRequest.variables['chkWrite' +x] == 'true') {
grRequest.description += ", Write";
}
if (grRequest.variables['chkExecute' + x] == 'true') {
grRequest.description += ", Execute";
}
}
} else {
if (grRequest.variables['chkWrite' + x] == 'true') {
grRequest.description += "Write";
if (grRequest.variables['chkExecute' + x] == 'true') {
grRequest.description += ", Execute";
}
} else {
grRequest.description += "Execute";
}
}
if (grRequest.variables['chkWrite' + x] == 'true') {
grRequest.description += "\n - Altering Data: " + grRequest.variables['ynAlter' + x];
if (grRequest.variables['ynAlter' + x] == 'Yes') {
grRequest.description += "\n - Data Altered: " + grRequest.variables['txtDataAltered' + x] +
"\n - Contains PII: " + grRequest.variables['ynPII' + x];
}
}
if (x < intDatabases) {
grRequest.description += "\n";
}
}
grRequest.update();