• only_me
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi there,

I have read many documents and learnt a lot about SalesForce, but am still unable to do a simple task that is call one single API function 'setPassword' in javascript..

The result I am getting is "Invalid ID"..

I have tried both with the 15 character ID, and the 18 character ID..

Currently I have the code loaded into an SControl and have it displaying on the contacts page..I have attached the HTML contents of the SControl below.. Can you please either confirm it is supposed to work? Or comment on how to fix my broken code?

This is created as an SControl, and added to the users information page in salesforce..

All I want to do is reset their password for the Self Service Portal (Cases) to a password that I directly specify..

I also noticed that SalesForce uses 2 (yes, two) identifying ID's for everything.. One which is 15 characters long - case sensitive, and used throughout the SalesForce.com website - and another which is 18 characters long - not case sensitive and used throughout the APIs'.. I have had to write a function to determine the 18 character code based upon other forum users comments.. Can you please answer why there is two IDs to begin with? And also if my javascript code is correct to generate the appropriate ID for using with the SalesForce API?

If my javascript code (Convert15to18ID) is correct, then others are more than welcome to use it for their needs.. Otherwise, please help me fix it!

If I have got it completely wrong, then please let me know!


Code:
<script type="text/javascript" src="/soap/ajax/8.0/connection.js"></script>
<script type="text/javascript">
function Convert15to18ID(InID)
{
  // Converts a 15 character ID to an 18 character, case-insensitive one ...
  var InChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
  var InUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  var Result = '';
  var tmpGroup = '';

  var iVal = new Array(5)

  iVal[0] = 0;
  iVal[1] = 1;
  iVal[2] = 2;
  iVal[3] = 4;
  iVal[4] = 8;
  iVal[5] = 16;


  var tmpGroup = 0;
  var bFirstTime = true;

  for (var i = 14; i >= 0; i--)
  {

    if (((i % 5) == 0) && (bFirstTime == false))
    {
      Result = InUpper.substring(tmpGroup, tmpGroup + 1) + Result;
      tmpGroup = 0;
    }

    if (InUpper.indexOf(InID.substring(i, i + 1)) >= 0)
    {
      tmpGroup = tmpGroup + iVal[(5 - (i % 5))];
    }

    bFirstTime = false;
  }

  return InID + Result;
}
function setPasswordSuccess() {alert('Password Reset Success');}
function setPasswordFail() {alert('Password Reset FAILED');}
</script>
<a href="javascript&colon;sforce.connection.setPassword(Convert15to18ID('{!Contact.Id}'), '{!Contact.newPassword}', {onSuccess:setPasswordSuccess, onFailure:setPasswordFail});">Reset Self-Service Portal Password</a>

 


Message Edited by only_me on 03-06-2007 02:11 PM

Hi there,

I have read many documents and learnt a lot about SalesForce, but am still unable to do a simple task that is call one single API function 'setPassword' in javascript..

The result I am getting is "Invalid ID"..

I have tried both with the 15 character ID, and the 18 character ID..

Currently I have the code loaded into an SControl and have it displaying on the contacts page..I have attached the HTML contents of the SControl below.. Can you please either confirm it is supposed to work? Or comment on how to fix my broken code?

This is created as an SControl, and added to the users information page in salesforce..

All I want to do is reset their password for the Self Service Portal (Cases) to a password that I directly specify..

I also noticed that SalesForce uses 2 (yes, two) identifying ID's for everything.. One which is 15 characters long - case sensitive, and used throughout the SalesForce.com website - and another which is 18 characters long - not case sensitive and used throughout the APIs'.. I have had to write a function to determine the 18 character code based upon other forum users comments.. Can you please answer why there is two IDs to begin with? And also if my javascript code is correct to generate the appropriate ID for using with the SalesForce API?

If my javascript code (Convert15to18ID) is correct, then others are more than welcome to use it for their needs.. Otherwise, please help me fix it!

If I have got it completely wrong, then please let me know!


Code:
<script type="text/javascript" src="/soap/ajax/8.0/connection.js"></script>
<script type="text/javascript">
function Convert15to18ID(InID)
{
  // Converts a 15 character ID to an 18 character, case-insensitive one ...
  var InChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
  var InUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  var Result = '';
  var tmpGroup = '';

  var iVal = new Array(5)

  iVal[0] = 0;
  iVal[1] = 1;
  iVal[2] = 2;
  iVal[3] = 4;
  iVal[4] = 8;
  iVal[5] = 16;


  var tmpGroup = 0;
  var bFirstTime = true;

  for (var i = 14; i >= 0; i--)
  {

    if (((i % 5) == 0) && (bFirstTime == false))
    {
      Result = InUpper.substring(tmpGroup, tmpGroup + 1) + Result;
      tmpGroup = 0;
    }

    if (InUpper.indexOf(InID.substring(i, i + 1)) >= 0)
    {
      tmpGroup = tmpGroup + iVal[(5 - (i % 5))];
    }

    bFirstTime = false;
  }

  return InID + Result;
}
function setPasswordSuccess() {alert('Password Reset Success');}
function setPasswordFail() {alert('Password Reset FAILED');}
</script>
<a href="javascript&colon;sforce.connection.setPassword(Convert15to18ID('{!Contact.Id}'), '{!Contact.newPassword}', {onSuccess:setPasswordSuccess, onFailure:setPasswordFail});">Reset Self-Service Portal Password</a>

 


Message Edited by only_me on 03-06-2007 02:11 PM