Docusign Signer Name - javascript

At my current company we have DocuSign integrated with Salesforce for sending out contracts to our potential clients.
Each contract is required to be signed by our potential client but also from our VP of sales/services.
I created a custom button on the quote object to submit the quote to DocuSign passing the information required (Signer Role, name, email etc) The problem I am having is that for some reason the full name of the second signer (the internal signer) does not get passed on to DocuSign so the sales rep has to manually go and edit the recipients each time and add the name.
Button code:
var quoteApproved = {!Quote.Quote_Approved__c};
//********* Option Declarations (Do not modify )*********//
var RC = '';
var RSL = '';
var RSRO = '';
var RROS = '';
var CCRM = '';
var CCTM = '';
var CCNM = '';
var CRCL = '';
var CRL = '';
var OCO = '';
var DST = '';
var LA = '';
var CEM = '';
var CES = '';
var STB = '';
var SSB = '';
var SES = '';
var SEM = '';
var SRS = '';
var SCS = '';
var RES = '';
//*************************************************//
switch ("{!Quote.Signed_by__c}") {
case "John Cash":
CRL = "Email~john.cash#company.com; FirstName~John; LastName~Cash; Role~Signer 2; RoutingOrder~1";
CCTM = "Signer 2~Signer";
break;
case "Mark Cash":
CRL = "Email~mark.cash#company.com; FirstName~Mark; LastName~Cash; Role~Signer 2; RoutingOrder~1";
CCTM = "Signer 2~Signer";
}
if (quoteApproved) {
{
!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")
}
var sourceId = DSGetPageIDFromHref();
var RQD = DSGetPageIDFromHref();
window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID=" + sourceId + "&CCTM=" + CCTM + "&CRL=" + CRL + "&RQD=" + RQD;
} else {
alert("Your quote has not been approved yet. \nPlease submit for approval before sending the contract.");
}

I have resolved the issue. The RQD variable was adding a # at the end of the URL preventing the completion of the field mapping.

Related

Email is not sending

Code Runs No Errors But I Do Not Receive and email when I check my gmail
This line is the issue I believe I am writing this incorrectly so its not sending the email help please
if(values.getDisplayValues() === "On-going" || values.getDisplayValues() === "" && values1.getDisplayValues() >= 80)
Rest of the code:
function sendEmail(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var SpreadsheetID = ss.getSheetId();
var spreadsheetURL = ss.getUrl();
var SpreadsheetID = spreadsheetURL.split("/")[5];
var filterViewName = 'PO_Log Precentage';
var filterViewID = filterId(SpreadsheetID, filterViewName);
var url = createURL(spreadsheetURL, filterViewID);
Logger.log(url);// Testing to see the correct url is created
var po_numID = ss.getSheetByName("Purchase Orders List").getRange("A2").getDisplayValue().substr(0,3);
Logger.log(po_numID);
var email_va = ss.getSheetByName("Purchase Orders List");
var values = email_va.getRange("Q2:Q");
var values1 = email_va.getRange("T2:T");
Logger.log(values)
var emailDataSheet = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/17G0QohHxjuAcZzwRtQ6AUW3aMTEvLnmTPs_USGcwvDA/edit#gid=1242890521").getSheetByName("TestA");
Logger.log(emailDataSheet.getSheetName());
var emailData = emailDataSheet.getRange("A2:A").getDisplayValues().flat().map(po => po.substr(0,3));
Logger.log(emailData)
var subject = po_numID + " Po Log Daily Notification ";
var options = {}
options.htmlBody = "Hi All, " + "The following" + '<a href=\"' +url+ '" > Purchase Orders </a>' + "are over 80% spent" + "";
// I believe this if statement is the problem I am writing it in correctly
if(values.getDisplayValues() === "On-going" || values.getDisplayValues() === "" && values1.getDisplayValues() >= "80%"){
emailData.every((po, index) => {
if (po == po_numID){
const email = emailDataSheet.getRange(index + 2,7).getValue();
console.log(email);
MailApp.sendEmail(email, subject, '', options);
return false;
} else {
return true;
}
});
}
}
https://docs.google.com/spreadsheets/d/1QW5PIGzy_NSh4MT3j_7PggxXq4XcW4dCKr4wKqIAp0E/edit#gid=611584429
Here is the spread sheet
values.getDisplayValues() gives you an array.
Basically it makes no sense to compare an array and a string with === and >= etc.
You need to decide which element of the array there should be. May be something like values.getDisplayValues()[0][0] (because it's likely an 2D-array). I can't check your code, so just a guess.

Safari browser not running my code properly?

I have the following class:
class Portal {
caption = "";
thumbnailURL = "";
profileImgURL = "";
mp3 = "";
timestamp = 0.0;
username = "";
uid = "";
num = 0;
// var caption = new String();
// var caption = "";
// var thumbnailURL = "";
// var profileImgURL = "";
constructor(cap, thumb, prof, mp3, timestamp, username, uid) {
this.caption = cap;
this.thumbnailURL = thumb;
this.profileImgURL = prof;
this.mp3 = mp3;
this.timestamp = timestamp;
this.username = username;
this.uid = uid;
}
}
When I run this on safari brower I get the two bellow errors.
SyntaxError: Unexpected token '='. Expected an opening '(' before a method's parameter list.
And then despite running the script for the portal class before the main.js script I get this:
Unhandled Promise Rejection: ReferenceError: Can't find variable: Portal
How do I fix this?
Class field declarations are not finalised, so I suppose Safari is not yet supporting them. – VLAZ 3 mins ago
All that is needed is:
class Portal {
constructor(cap, thumb, prof, mp3, timestamp, username, uid) {
this.caption = cap;
this.thumbnailURL = thumb;
this.profileImgURL = prof;
this.mp3 = mp3;
this.timestamp = timestamp;
this.username = username;
this.uid = uid;
}
}

How do I make the right conditions for the url based on the value of a variable? (javascript)

My script javascript like this :
<script>
var url = 'http://my-app.test/item';
var sessionBrand = 'honda';
var sessionModel = 'jazz';
var sessionCategory = 'velg';
var sessionKeyword = 'RS 175/60 R 15';
if(sessionBrand)
var brand = '?brand='+sessionBrand;
else
var brand = '';
if(sessionModel)
var model = '&model='+sessionModel;
else
var model = '';
if(sessionCategory)
var category = '&category='+sessionCategory;
else
var category = '';
if(sessionKeyword)
var keyword = '&keyword='+this.sessionKeyword;
else
var keyword = '';
var newUrl = url+brand+model+category+keyword;
console.log(newUrl);
</script>
The result of console.log like this :
http://my-app.test/item?brand=honda&model=jazz&category=velg&keyword=RS 175/60 R 15
var sessionBrand, sessionModel, sessionCategory and sessionKeyword is dynamic. It can change. It can be null or it can have value
I have a problem
For example the case like this :
var sessionBrand = '';
var sessionModel = '';
var sessionCategory = '';
var sessionKeyword = 'RS 175/60 R 15';
The url to be like this :
http://my-app.test/item&keyword=RS 175/60 R 15
Should the url like this :
http://my-app.test/item?keyword=RS 175/60 R 15
I'm still confused to make the condition
How can I solve this problem?
Just use the array for params and then join them with & separator. For example:
var url = 'http://my-app.test/item';
var sessionBrand = 'honda';
var sessionModel = 'jazz';
var sessionCategory = 'velg';
var sessionKeyword = 'RS 175/60 R 15';
var params = [];
if (sessionBrand) {
params.push('brand=' + sessionBrand);
}
if (sessionModel) {
params.push('model=' + sessionModel);
}
if(sessionCategory) {
params.push('category=' + sessionCategory);
}
if(sessionKeyword) {
params.push('category=' + sessionCategory);
}
var newUrl = url + '?' + params.join('&');
console.log(newUrl);
The problem with your code is that it is prefacing all query parameters with a & - except for the sessionBrand. What you need in a URL is for the first parameter to start with a ?, and all others with a &. As you saw, your code doesn't do this when there is no sessionBrand.
There are number of ways to fix this. Probably the neatest I can think of is to assemble the various parts as you are, but without any prefixes - then join them all together at the end. Like this (I just saw Viktor's solution, it's exactly the same idea, but neater because he rewrote more of your earlier code):
if(sessionBrand)
var brand = 'brand='+sessionBrand;
else
var brand = '';
if(sessionModel)
var model = 'model='+sessionModel;
else
var model = '';
if(sessionCategory)
var category = 'category='+sessionCategory;
else
var category = '';
if(sessionKeyword)
var keyword = 'keyword='+this.sessionKeyword;
else
var keyword = '';
var queryString = '?' + [sessionBrand, sessionModel, sessionCategory, sessionKeyword].filter(function(str) {
return str.length > 0;
}).join("&");
var newUrl = url+queryString;

Javascript Send mail on Gmail with signature and BCC with Google Spreadsheet

Is there a way with Javascript (or other) from Google Spreadsheet to get the Gmail account signature?
Details:
I have a Google spreadsheet with information in it.
When clicking on a button, it identifies who has to receive the information, prepare a mail, and send it to the person.
However, I want to add the sender's signature at the end of the mail (it includes name, phone, logo, etc.).
I'm open if I get the signature from an other place, as long as it can change according to who's sending the mail.
This is for my volunteering association, not a job.
In case my code may help (I look to fill the var Signature):
var Signature;
var Receivers;
var Subject;
var Location ;
var MailtoSend= "Hello, \n\n The next meeting will be at " + Location + ". \n" + Signature;
MailApp.sendEmail(Receivers, Subject, MailtoSend);
SOLUTION:
I've find a way from another site (can't find it):
Create a template in your gmail draft with your signature, and put in the subject "Template" and in the body {Body}.
Then use the following code to create a copy of the mail, and fill it with all the information:
In the function to send the mail add:
sendGmailTemplate(RecipientTo, RecipientCC, RecipientBCC, SujetAEnvoyer, CourrielAEnvoyer);
Referring to the following functions:
function sendGmailTemplate(RecipientTo, RecipientCC, RecipientBCC, subject, body, options) { //mettre à jour la quantité de recipeien cc bcc to
options = options || {}; // default is no options
var drafts = GmailApp.getDraftMessages();
var found = false;
for (var i=0; i<drafts.length && !found; i++) {
if (drafts[i].getSubject() == "Template") {
found = true;
var template = drafts[i];
}
}
if (!found) throw new Error( "Impossible de trouver le brouillon 'Template' sur le gmail" );
// Generate htmlBody from template, with provided text body
var imgUpdates = updateInlineImages(template);
options.htmlBody = imgUpdates.templateBody.replace('{BODY}', body);
options.attachments = imgUpdates.attachments;
options.inlineImages = imgUpdates.inlineImages;
options.cc = RecipientCC;
options.bcc = RecipientBCC;
options.replyTo = "";
return GmailApp.sendEmail(RecipientTo, subject, body, options);
}
function updateInlineImages(template) {
//////////////////////////////////////////////////////////////////////////////
// Get inline images and make sure they stay as inline images
//////////////////////////////////////////////////////////////////////////////
var templateBody = template.getBody();
var rawContent = template.getRawContent();
var attachments = template.getAttachments();
var regMessageId = new RegExp(template.getId(), "g");
if (templateBody.match(regMessageId) != null) {
var inlineImages = {};
var nbrOfImg = templateBody.match(regMessageId).length;
var imgVars = templateBody.match(/<img[^>]+>/g);
var imgToReplace = [];
if(imgVars != null){
for (var i = 0; i < imgVars.length; i++) {
if (imgVars[i].search(regMessageId) != -1) {
var id = imgVars[i].match(/realattid=([^&]+)&/);
if (id != null) {
var temp = rawContent.split(id[1])[1];
temp = temp.substr(temp.lastIndexOf('Content-Type'));
var imgTitle = temp.match(/name="([^"]+)"/);
if (imgTitle != null) imgToReplace.push([imgTitle[1], imgVars[i], id[1]]);
}
}
}
}
for (var i = 0; i < imgToReplace.length; i++) {
for (var j = 0; j < attachments.length; j++) {
if(attachments[j].getName() == imgToReplace[i][0]) {
inlineImages[imgToReplace[i][2]] = attachments[j].copyBlob();
attachments.splice(j, 1);
var newImg = imgToReplace[i][1].replace(/src="[^\"]+\"/, "src=\"cid:" + imgToReplace[i][2] + "\"");
templateBody = templateBody.replace(imgToReplace[i][1], newImg);
}
}
}
}
var updatedTemplate = {
templateBody: templateBody,
attachments: attachments,
inlineImages: inlineImages
}
return updatedTemplate;
}
There is not a method to request a signature that you have already created. It is possible to create one yourself with inlineImages. The documentation for that can be found here: https://developers.google.com/apps-script/reference/gmail/gmail-app#sendemailrecipient-subject-body-options

Adobe AIR readLine

I need to process a text file one line at a time. In BASIC, I could use a readline command, which would read until the next carriage return/line feed.
How would you write a function for looping through a file one line at a time in AIR?
var myDir = air.File.documentsDirectory;
var myFile = myDir.resolvePath("Test.txt");
if (myFile.exists) {
var myFileStream = new air.FileStream();
myFileStream.open(myFile, air.FileMode.READ);
var myByteArray = new air.ByteArray();
myFileStream.readBytes(myByteArray,0,myFileStream.bytesAvailable);
air.Introspector.Console.log(myByteArray.length);
} else {
alert ('File not found.');
}
var LineNumber;
var ItemCode;
var OrderCode;
var Qty;
var myDir = air.File.documentsDirectory;
var myFile = myDir.resolvePath("Test.txt");
if (myFile.exists) {
var myFileStream = new air.FileStream();
myFileStream.open(myFile, air.FileMode.READ);
var myData = new air.ByteArray();
myFileStream.readBytes(myData,0,myFileStream.bytesAvailable);
var str = myData.toString();
var Pos = 0;
var Tab = 0;
var CRLF = 0;
EOL = str.indexOf("\r",Pos);
while (EOL > 0) {
Tab = str.indexOf('\t',Pos);
LineNumber = str.substring(Pos,Tab);
Pos = Tab + 1;
Tab = str.indexOf('\t',Pos);
ItemCode = str.substring(Pos,Tab);
Pos = Tab + 1;
Tab = str.indexOf('\t',Pos);
OrderCode = str.substring(Pos,Tab);
Pos = Tab + 1;
CRLF = str.indexOf('\r',Pos);
Qty = str.substring(Pos,CRLF);
Pos = EOL+1;
EOL = str.indexOf("\r",Pos);
}
} else {
alert ('File not found.');
}

Categories

Resources