+ Start a Discussion
only_meonly_me 

Javascript, SControls and setPassword issues, with Self Service Users..

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

DevAngelDevAngel
To post code, use the SRC button in the message body editor of these forums.  I can't see your entire post.
SuperfellSuperfell
setPassword takes the usersId (Id of User object or SelfServiceUser object), not the contactId that you're trying to pass in.
DevAngelDevAngel
Good point Simon.  The selfservice user id is not the same id as the contact id who has been self service enabled.
only_meonly_me
My apologies to you all, I'm kinda new to the whole forums thing.. I have updated my initial post..

What you are saying does make sense, however where do I find this Self service user ID that you speak of?

Also did any of you get the chance to confirm my javascript code for accuracy? If it is accurate, I would like to see a javascript version in the main help files (as well as the C and Java examples), it doesn't have to be my code exactly, but having an example there will surely help many others!
zakzak
You can run a query to find the selfServiceUserId for a contact

select id from selfserviceUser where contactId='{Contact.Id}' and isActive=TRUE

You also don't need the do the 15/18 conversion yourself, the API will automatically take care of that.