Basic Template for Common Tasks
Basic Template
Use the following template for a basic DIAL script.
diveline.set_webdir("/di_solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("__________");
model.open(model,"___________");
marker.open(marker,"___________");
console.writeln("_____");
console.writeln("Script Complete");
diveline.disconnect();
Common Tasks
The following examples illustrate tasks commonly carried out by using DIAL scripts.
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("myProject");
// Specify the mail server and the string that appears as the email sender address
mail.set_server("mail.corp.com");
mail.set_from("[email protected]");
// Open a marker, save the report as a pdf file, and send the file as an attachment
marker.open(MARKER_,"/models/workshop3.mrk");
marker.save_window(MARKER_,"../temp/workshop3.pdf","pdf");
mail.file("[email protected]","Workshop3","../temp/workshop3.pdf","pdf,attach,filename=workshop3.pdf");
// Write log messages and disconnect from the server
console.writeln("Mail sent");
console.writeln("Script Complete");
diveline.disconnect();
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("myProject");
// Specify the mail server and the string that appears as the email sender address
mail.set_server("mail.corp.com");
mail.set_from("[email protected]");
// Create two arrays
QUICKVIEW = array.new();
QUICKVIEW_VALUE = array.new();
// Add the value "Commodity" to the QUICKVIEW array to name the QuickView
array.add(QUICKVIEW, "Commodity");
// Add the value "Asparagus" to the QUICKVIEW_VALUE array for the location value or named group
array.add(QUICKVIEW_VALUE, "Asparagus");
// Open marker with the QuickView value set as specified in the arrays and save the report
marker.open(MARKER_,"/cbases/mrk_002.mrk", QUICKVIEW, QUICKVIEW_VALUE);
marker.save_window(MARKER_,"../temp/mrk_002.pdf","pdf");
// Send the file to users
mail.file("[email protected],[email protected]","Bad Product Scanned","../temp/mrk_002.pdf","pdf,attach,filename=mrk_002.pdf");
// Write a log message and disconnect from the server
console.writeln("Script Complete");
diveline.disconnect();
diveline.set_webdir("di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("myProject");
// Specify the mail server and the string that appears as the email sender address
mail.set_server("10.10.10.19");
mail.set_from("[email protected]");
// Convert the arguments that are passed from the parent script to variables
CLIENTID=arg.get(1);
SPECIALTY=arg.get(2);
EMAIL=arg.get(3);
ALIAS=arg.get(4);
// Generate time and date variables
TIME = now();
TODAY = replace(today(),"/","-");
// Generate email subject line
SUBJECT_TEXT = "Company " + SPECIALTY + " Report - " + TODAY;
// Generate a variable that points to the location of the text file that includes the email body
BODY_PATH = "/cbases/demo_drl.txt";
// Generate a variable that points to the report file to send
REPORT_PATH = "../temp/Report_"+ TODAY + ".pdf";
// Generate a variable that points to the location of the marker
MARKER_PATH = "/models/customer.mrk";
// Open the marker and save the report as a pdf file
marker.open(MARKER_,MARKER_PATH);
marker.save_window(MARKER_,REPORT_PATH,"pdf");
// Send an email with subject line, body text, and the file attachment
mail.multipart(EMAIL, SUBJECT_TEXT, REPORT_PATH,"attach", BODY_PATH, "text");
// Write details to log file and disconnect from the server
console.writeln("Report sent to ClientID: " + CLIENTID + ", on " + TODAY + ", at " + TIME + ".");
console.writeln("The email addresses copied: " + EMAIL + ".");
diveline.disconnect();
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("myProject");
// Specify the mail server and the string that appears as the email sender address
mail.set_server("mail.corp.com");
mail.set_from("[email protected]");
// Specify the file to attach to the email
mail.file("[email protected]","Test DIAL","/di/projects/myProject/data/test_file.txt","attach");
// Write a log message and disconnect from the server
console.writeln("Script Complete");
diveline.disconnect();
This script sends an email with a file attachment. The name of the attached file is different from the name of the file on disk. In this example script, the sender attaches the file named test_file.txt, and the recipient receives the attached filed with the name test.txt. The content of the file is the same; just the file name is different.
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("myProject");
// Specify the mail server and the string that appears as the email sender address
mail.set_server("mail.corp.com");
mail.set_from("[email protected]");
// Attach the file named test_file.txt and send it, with the name test.txt, to the recipient
mail.file("[email protected]","Test DIAL","/di/projects/myProject/data/test_file.txt","attach,filename=test.txt");
// Write a log message and disconnect from the server
console.writeln("Script Complete");
diveline.disconnect();
This script sends an email with a file attachment where the file name includes the current date The script shows two ways to use a variable and the plus sign (+) to create the file name string, such as test_2020-12-08.txt, within the mail.file() function.
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
// Specify the mail server and the string that appears as the email sender address
mail.set_server("mail.corp.com");
mail.set_from("[email protected]");
// Set the variable ZIPFILE to a file name that includes the date, such as test_2021-03-18.txt
ZIPFILE = concat("test_",replace(today(),"/","-"),".txt");
// Mail the file by using the ZIPFILE variable as the file name that the recipient receives
mail.file("[email protected]","Test DIAL","/di/projects/myProject/data/test_file.txt","attach,filename="+ZIPFILE);
// Alternatively, set a variable to the date and concatenate the file name in the mail.file() function
// Set the variable TODAY to a date string, such as 2021-03-18
// TODAY = replace(today(),"/","-");
// Mail the file that is named by concatenating text with the TODAY string and the file extension
mail.file("[email protected]","Test DIAL","/di/projects/myProject/data/test_file.txt","attach,filename=test_"+TODAY+".txt");
// Write a message to the log file and disconnect from the server
console.writeln("Script Complete");
diveline.disconnect();
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("myProject");
// Specify the mail server and the string that appears as the email sender address
mail.set_server("mail.corp.com");
mail.set_from("[email protected]");
// Open a marker (with Customer as a parent window)
marker.open(MARKER_,"/models/test_marker.mrk");
// Dive on each Customer, save the report as a pdf file, and send the email, one per Customer, with the file attachment
walk(MARKER_,"Customer")
{
COMMODITY = Dimension[MARKER_.Commodity];
SALESPERSON = Dimension[MARKER_.Salesperson];
marker.save_window(MARKER_,"/di/projects/myProject/temp/Revenue_"+COMMODITY+".pdf","pdf");
mail.file("[email protected]","Revenue for "+ SALESPERSON,"/di/projects/myProject/temp/Revenue_"+COMMODITY+".pdf","pdf,attach,filename=Revenue_"+COMMODITY+".pdf");
console.writeln("shipments_orders for "+SALESPERSON+" sent");
}
// Write a message to the log file and disconnect from the server
console.writeln("Script Complete");
diveline.disconnect();
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("myProject");
// Specify the mail server and the string that appears as the email sender address
mail.set_server("mail.corp.com");
mail.set_from("[email protected]");
// Open a marker (with Customer as a parent window)
marker.open(MARKER_,"/models/test_marker.mrk");
// Dive on each Customer Account SalesRep ID
// Check a lookup table to see if there is an email address for that rep
// If so, saves a pdf file and send the file as an attachment to that rep
lookup.open(LOOKUP_,"/di/projects/myProject/data/an_salesmanagerlu.txt","Sales Manager");
walk(MARKER_,"Customer")
{
if (lookup.defined(LOOKUP_) AND LOOKUP_.email != "")
{
SALES_MANAGER = Dimension[MARKER_.Sales Manager];
marker.save_report(MARKER_,"/temp/Sales_Revenue_for_"+SALES_MANAGER+".pdf","pdf");
mail.file(LOOKUP_.email,"Sales_Revenue_for_ "+SALES_MANAGER,"/temp/Sales_Revenue_for_"+SALES_MANAGER+".pdf","pdf,attach,filename=Sales_Revenue_for_"+SALES_MANAGER+".pdf");
console.writeln("Sales_Revenue_Report for "+SALES_MANAGER+" sent");
}
}
// Write a message to the log file and disconnect from the server
console.writeln("Script Complete");
diveline.disconnect();
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("myProject");
// Specify the mail server and the string that appears as the email sender address
mail.set_server("mail.corp.com");
mail.set_from("[email protected]");
// Open a marker (with Customer Account SalesRep ID as a parent window)
marker.open(MARKER_,"/models/test_marker.mrk");
// Dive on each Customer Account SalesRep ID
// Check a lookup table to see if there is an email address for that rep
// If there is an email address and a report for the rep, save the report as a pdf file and send it to the rep
// Else, if there is either no email address or no report, write a message to the log file
lookup.open(LOOKUP_,"/di/projects/myProject/data/an_salesmanagerlu.txt","Sales Manager");
walk(MARKER_,"Customer")
{
if (lookup.defined(LOOKUP_) AND LOOKUP_.email != "")
{
SALES_MANAGER = Dimension[MARKER_.Sales Manager];
if (window.is_empty(MARKER_))
{
console.writeln("Sales Revenue Report for "+SALES_MANAGER+" not sent");
}
else
{
marker.save_report(MARKER_,"/temp/Sales_Revenue_for_"+SALES_MANAGER+".pdf","pdf");
mail.file(LOOKUP_.email,"Sales_Revenue_for_"+SALES_MANAGER,"/temp/Sales_Revenue_for_"+SALES_MANAGER+".pdf","pdf,attach,filename=Sales_Revenue_for_"+SALES_MANAGER+".pdf");
console.writeln("Sales Revenue Report for "+SALES_MANAGER+" sent");
}
}
}
// Write a message to the log file and disconnect from the server
console.writeln("Script Complete");
diveline.disconnect();
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user","ditok-s4OEt2BE29XqkTXhntdp");
diveline.set_project("myProject");
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user",arg.get(1));
diveline.set_project("myProject");
diveline.set_webdir("/di/solution/dl-dataroot/webdir");
diveline.connect("localhost","dial_user");
diveline.set_project("myProject");
// Open a marker (with Customer Account as a parent window)
marker.open(MARKER,"/models/test_marker.mrk");
lookup.open(LOOKUP,"/di/projects/myProject/data/an_salesmanagerlu.txt","Sales Manager");
// Walk through each customer in the report and determine if it meets the specified exception criteria.
// If the case revenue is less than 20% from the last quarter, an email is sent to the sales rep responsible for each customer
// The if() statement checks for three conditions:
// 1) Check to see if the lookup exists.
// 2) Check to see if salesperson's email address exists.
// 3) Check to see if customers exist for that salesperson meeting the exception criteria.
// If all three conditions are true, send an email to the salesperson; if any of the three conditions are false, no email is sent.
walk(MARKER,"Customer")
{
if (lookup.defined(LOOKUP) AND LOOKUP.Email != "" AND !(window.is_empty(MARKER)))
{
REP = Dimension[MARKER.Salesperson];
marker.save_report(MARKER,"/temp/dial_declined_revenue_"+REP+".pdf","pdf");
mail.test();
mail.set_server("mail.corp.com");
mail.set_from("[email protected]");
mail.file(LOOKUP.SalesRepEmail,"Declined revenue for "+REP,
"/temp/dial_declined_revenue_"+REP+".pdf",
"pdf,attach,filename=dial_declined_revenue_"+REP+".pdf");
}
}
// Write a message to the log file and disconnect from the server
console.writeln("Script Complete");
diveline.disconnect();
The following script handles a DiveBook with 100+ internally saved Markers. This script saves the Markers to individual files and creates a new DiveBook that just has the links.
// Set parameters
output_system_path = "/di/projects/spectre/";
output_db_name = "auto_db.dbk";
input_project = "All my Spectre Projects";
input_divebook = "/divebook.dbk";
diveline_server = "localhost:2130";
diveline_user = "jenny";
diveline_webdir = "/di/solution/dl-dataroot-70/webdir/";
// Connect to the DiveLine server and open the DiveBook
diveline.set_webdir(diveline_webdir);
diveline.connect(diveline_server,diveline_user);
diveline.set_project(input_project);
divebook.open(mydb,input_divebook);
// Get the number of areas
areas = divebook.area_count(mydb);
i=1;
// Create the header for the new divebook that is created
new_divebook = "version \"1\";" + calc.chr(10) + "object 'HEAD' \"File_Header\" {" + calc.chr(10) + "};"
+calc.chr(10) + "object 'AREA' \"Areas\" {" +calc.chr(10) + "Areas={" +calc.chr(10) ;
//Loop through all areas
while(i<=areas){
area = divebook.area_name(mydb,i);
console.writeln(area);
// Get the number of topics
topics = divebook.topic_count(mydb,area);
j=1;
// Add the area header to the DiveBook
new_divebook = new_divebook + "{" + calc.chr(10) + "Name=\"" + area + "\"," + calc.chr(10) + "Topics={" + calc.chr(10);
// Loop through the topics of the current area
while(j<=topics) {
topic = divebook.topic_name(mydb,area,j);
console.writeln(topic);
// Open the marker
divebook.open_topic(mydb,myreport,area,topic);
// Translate the area and topic names into valid filename strings
f_area = calc.map_filename(area);
f_topic = calc.map_filename(topic);
// Create the filename for the new marker and write it out
marker_name="/"+f_area + "_" + f_topic + ".mrk";
marker.save(myreport,marker_name);
// Add the topic to the new DiveBook
new_divebook = new_divebook + "{" + calc.chr(10)+ "Name=\"" + topic +"\"," + calc.chr(10)+
"Data={" + calc.chr(10) + "Data_Type=4," + calc.chr(10)+
"Link_Filename=\"" + marker_name +"\"" + calc.chr(10)+ "}" +calc.chr(10) + "}," + calc.chr(10);
j=j+1;
}
// Close the current area in the new DiveBook
new_divebook = new_divebook + "}," + calc.chr(10)+ "}," + calc.chr(10);
i=i+1;
}
// Close the new DiveBook
new_divebook = new_divebook + calc.chr(10) + "}" + calc.chr(10) + "};" + calc.chr(10) ;
// Define the filename for the new DiveBook.
outfile = output_system_path + output_db_name;
// ... and save it. Done!
file.open(myfile,outfile,"write");
file.write (myfile,new_divebook);
file.close(myfile);
// Write a message to the log file and disconnect from the server
console.writeln("All Done.");
diveline.disconnect();
Mentioned in: