HTML code for notification

HTML code for notification

PLM-Sylvain.Bailly
Collaborator Collaborator
1,550 Views
4 Replies
Message 1 of 5

HTML code for notification

PLM-Sylvain.Bailly
Collaborator
Collaborator

Hello,

 

Is it possible to have the HTML code that Autodesk use to send notifications? I would like to send the same email but when it is required in the workflow.

The code that I need is the one that you can see in attachment (tables and all the information linked to the workflow).

 

Thanks,

Sylvian

0 Likes
Accepted solutions (2)
1,551 Views
4 Replies
Replies (4)
Message 2 of 5

tony.mandatori
Autodesk
Autodesk

Sylvain,

 

Here is some code that I have used in the past.

 

function sendNotification(subject, userProperties, avp, includeWFLinks){
     
    var itemDmsid = dmsID;
    var wsId = workspaceID;
    var wfLastActions = item.workflowActions[0];
    var lastApprover = (getUserName(wfLastActions.userID)).split(',').reverse().join(', ');
    var tab = ['workflowactions', 'itemdetails'];
    var tenant = CONST_PLMTENANT+"/workspace#workspaceid="+wsId+"&dmsid="+itemDmsid+"&tab=";
 
    var email = new Email();
    email.subject = subject;
    var usersToTreat = userProperties.length;
    for(var prop in userProperties){
        if(prop === 'email'){
            email.body = getPrintView(avp);
             
            if (includeWFLinks) {
                email.body += '<br><b>'+userProperties.firstName+', a Workflow Action, has been performed by '+lastApprover;
                email.body += '<br>Currently there are Workflow Actions available to'+userProperties.firstName+" "+userProperties.lastName+'</br>';
                email.body += '<br><a href="'+tenant+tab[0]+'">Workflow Actions Available</a></br>';
            }
 
            email.body += '<br><br><a href="'+tenant+tab[1]+'">View Items details for '+subject+'</a></br></br>';
            email.to = userProperties.email;
            email.send();
        }
    }
     
} 

Note that the send is in the for loop.  We need to send each email independently.

Message 3 of 5

PLM-Sylvain.Bailly
Collaborator
Collaborator

Hi Tony,

 

Your script has inspired me but the most difficult was to do the tables.

Now, with few tests I have the result that you can see in attachment.

 

I have 2 problems:

- how is it possible to catch the name of the workspace? I only know how to take the ID of the workspace with "workspaceID"

- the date that I have on the second table is always in the EDT (Eastern Daylight Time) format. Is it the one of the Autodesk server which, I think that it is located in the East cost, of the USA. Is it right? Is it possible to be linked with the location of the user which receive the email?

 

 

 

Thanks,

Sylvain

0 Likes
Message 4 of 5

PLM-Sylvain.Bailly
Collaborator
Collaborator
Accepted solution

Here is the code if someone needs in the future (I am waiting the info of Tony for the name of the workspace and the date/hour):

 

// Send an email notification to each member of the groups "ADMIN [Sales EU]" and "ADMIN [Sales US]" to informed them that a NDA is signed
        var itemDmsid = dmsID;
        var wsId = workspaceID;
        var wfLastActions = item.workflowActions[0];
        var lastApprover = (getUserName(wfLastActions.userID)).split(',').reverse().join(' ');
        var tenantItemDetails = tenantName + "/workspace#workspaceid=" + wsId + "&dmsid=" + itemDmsid + "&tab=itemdetails";
        var usersGr01 = Security.listUsersInGroup('ADMIN [Sales EU]');
        var usersGr02 = Security.listUsersInGroup('ADMIN [Sales US]');
        
        // Content of the email
        var EmailSubject = 'NDA signed: ' + item.NAME;
        var EmailBody = '<h2><b>Customer Workflow Notification</b></h2>';
        EmailBody += '<br>A Confidential Agreement has been executed with <b>' + item.NAME + '</b> and the workflow transition <b>' + item.workflowActions[0].transition + '</b>, has been performed in <b>' + wsId + '</b> by <b>' + lastApprover + ' (' + wfLastActions.userID + ')</b>.';
        EmailBody += '<br><br><br><a href="' + tenantItemDetails +'">View Items details for: ' + item.NAME + '</a></br></br></br>';
        
        // Table of the 'Workflow Summary'
        EmailBody += '<table border: 1px solid white;><tr style="color: #ffffff;"><th colspan="2" style="text-align:left; background-color: #999999;">Workflow Summary</th></tr>';
        EmailBody += '<tr style="font-size: 12px; background-color: #e2e2e2;"><th style="text-align:left; width: 180px;">Workspace:</th><td style="width: 614px;">Customers</td></tr>';
        EmailBody += '<tr style="font-size: 12px; background-color: #e2e2e2;"><th style="text-align:left; width: 180px;">Item:</th><td style="width: 614px;">' + item.descriptor.descriptor + '</td></tr>';
        EmailBody += '<tr style="font-size: 12px; background-color: #e2e2e2;"><th style="text-align:left; width: 180px;">Current State:</th><td style="width: 614px;">' + item.descriptor.workflowState + '</td></tr>';
        EmailBody += '<tr style="font-size: 12px; background-color: #e2e2e2;"><th style="text-align:left; width: 180px;">Last Action:</th><td style="width: 614px;">' + item.workflowActions[0].transition + '</td></tr>';
        EmailBody += '<tr style="font-size: 12px; background-color: #e2e2e2;"><th style="text-align:left; width: 180px;">Performed By:</th><td style="width: 614px;">' + lastApprover + '</td></tr></table>';
        
        // Table of the actions for this object
        EmailBody += '<br><br><table border: 1px solid white;><tr style="color: #ffffff; background-color: #999999;"><th style="width: 60px;">Step</th><th style="width: 160px;">Date Time</th><th style="width: 120px;">Action</th><th style="width: 140px;">Performed By</th><th style="width: 310px;">Comments</th></tr>';
        // Loop on all steps done since the beginning
        for(var temp in item.workflowActions){
            var wfHistoryAction = item.workflowActions[temp];
            
            EmailBody += '<tr style="font-size: 12px; background-color: #e2e2e2;"><td style="width: 60px;">' + wfHistoryAction.step + '</td><td style="width: 160px;">' + wfHistoryAction.timeStamp + '</td><td style="width: 120px;">' + wfHistoryAction.transition + '</td><td style="width: 140px;">' + wfHistoryAction.userDisplayName + ' (' +wfHistoryAction.userID  + ')</td><td style="width: 310px;">' +wfHistoryAction.comments + '</td></tr>';
        }
        EmailBody += '</table></br></br>';
        
        // Send email to 'ADMIN [Sales EU]'
        for(var index in usersGr01){
            var email = new Email();
            
            email.subject = EmailSubject;
            email.body = EmailBody;
            email.to = usersGr01[index].email;
            email.send();
        }
Message 5 of 5

tony.mandatori
Autodesk
Autodesk
Accepted solution

Sylvain,

 

I usually hard code the Workspace names in  variables in an imported function.  I don't have any good way of reading the workspace name from the system.

 

As for dates, you can use toUTCString() to get the GMT date.  You can also use getTimezoneOffset() to get the current offset based on the timezone.  Since JavaScript is running on the server, it is using the server's time/date locale - you can try to convert to a different local by writing a function to change the offset.

 

I found this link which discusses some alternatives - https://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript 

 

I think this is the best one in our case

/** 
 * function to calculate local time
 * in a different city
 * given the city's UTC offset
 */
function calcTime(city, offset) {

    // create Date object for current location
    var d = new Date();

    // convert to msec
    // add local time zone offset
    // get UTC time in msec
    var utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    // create new Date object for different city
    // using supplied offset
    var nd = new Date(utc + (3600000*offset));

    // return time as a string
    return "The local time in " + city + " is " + nd.toLocaleString();
}