function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HarmpieHarmpie 

Merge fields and Id's

I am running into a problem using an Apexchange application FTP attachments pro. This application requires to set up custom links that embed the record Id. Using merge fields, the 15 character Id is returned, however, the application requires the 18 character Id to be passed (using a case insensitive FTP server)! Is there a way to convert the 15 char Id within the custom link to the 18 char variant ?
HarmpieHarmpie
Problem solved. Made a conversion snippet-control to transform Id 15 to Id 18, works like a charm.
shCalgaryshCalgary
We are just implementing FTP Attachments Pro, and I am at the stage of needing to customize the custom links that were installed with the evaluation version to point to our own application server.
 
The problem is that FTP Attachments pro is flagged as "Managed" so I am unable to update the links.
 
Did anyone run into this same issue, and what is the work-around.;
 
thanks,
Steve Hume
SFDC Project Manager
Trimac Transportation
 
HarmpieHarmpie
1) Copy the link´s code
2) Create new custom button or link and paste the code in.
3) Customize the code where necessary
4) Remove original link(s) from the appropriate page layout
5) Add new button(s)/link(s) to the page layout
KCKKCK
Hello - I have the same problem converting 15 char merge fields.  Please can you post the snippet you created? 
 
Thanks.
HarmpieHarmpie
Code:
function convertId15Toid18(id) {
 var id15 = id;
 var convTable = [];
 convTable['00000']= "A";
 convTable['00001']= "B";
 convTable['00010']= "C";
 convTable['00011']= "D";
 convTable['00100']= "E";
 convTable['00101']= "F";
 convTable['00110']= "G";
 convTable['00111']= "H";
 convTable['01000']= "I";
 convTable['01001']= "J";
 convTable['01010']= "K";
 convTable['01011']= "L";
 convTable['01100']= "M";
 convTable['01101']= "N";
 convTable['01110']= "O";
 convTable['01111']= "P";
 convTable['10000']= "Q";
 convTable['10001']= "R";
 convTable['10010']= "S";
 convTable['10011']= "T";
 convTable['10100']= "U";
 convTable['10101']= "V";
 convTable['10110']= "W";
 convTable['10111']= "X";
 convTable['11000']= "Y";
 convTable['11001']= "Z";
 convTable['11010']= "0";
 convTable['11011']= "1";
 convTable['11100']= "2";
 convTable['11101']= "3";
 convTable['11110']= "4";
 convTable['11111']= "5";
 
 function isUpperCase(str) {
  if(str=='0' || str=='1' || str=='2' || str=='3' || str=='4' || str=='5' || str=='6' || str=='7' || str=='8' || str=='9' || str=='0') {
   return false; 
  } else {
   var testString = new String(str);
   var upperVariant = testString.toUpperCase();
   if(testString == upperVariant) {
    return true;
   } else {
    return false;
   }
  }
 }
 var stringToChunk = new String(id15);
 var chunk1 = stringToChunk.substr(0,5);
 var chunk2 = stringToChunk.substr(5,5);
 var chunk3 = stringToChunk.substr(10,5);
 
 var chunk1Conv = "";
 var chunk2Conv = "";
 var chunk3Conv = "";
 
 for(x=4;x>=0;x--) {
  if(isUpperCase(chunk1.charAt(x))) {
   chunk1Conv+="1";
  } else {
   chunk1Conv+="0"; 
  }
 }
 for(x=4;x>=0;x--) {
  if(isUpperCase(chunk2.charAt(x))) {
   chunk2Conv+="1";
  } else {
   chunk2Conv+="0"; 
  }
 }
 for(x=4;x>=0;x--) {
  if(isUpperCase(chunk3.charAt(x))) {
   chunk3Conv+="1";
  } else {
   chunk3Conv+="0"; 
  }
 }
 var suffix = convTable[chunk1Conv]+convTable[chunk2Conv]+convTable[chunk3Conv];
 var id18 = id15+suffix;
 return id18;
}

 
As you can see, it takes a 15bit Id and returns and 18bit version....
KCKKCK
Thanks for posting the code Harmpie!

Actually, I found another version of it that seems to work perfectly:

function normaliseSforceID( id) { // fluff up a 15 char id to return an 18 char id
 if (id == null) return id;
 id = id.replace(/\"/g, ''); // scrub quotes from this id
 if (id.length != 15) {
  //print('well, id is not 15, bye' + id + ' ' + id.length);
  return null;
 }
 var suffix = "";
 for (var i = 0; i < 3; i++) {
  var flags = 0;
  for (var j = 0; j < 5; j++) {
   var c = id.charAt(i * 5 + j);
   if (c >= 'A' && c <= 'Z') {
    flags += 1 << j;
   }
  }
  if (flags <= 25) {
   suffix += "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(flags);
  } else {
   suffix += "012345".charAt(flags-26);
  }
 }
 return id + suffix;
}



HarmpieHarmpie
Less code: better script :)