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
jyotijyoti 

Custom screen dropdown using Salesforce.com data

I have created a custom screen with Accounts owned by a specific user using an S-Control with HTML to build the page .  In this screen, someone would reassign the Account records to a new user by selecting a user.
 
Question:  Is there a way for me to query the User table to automatically populate the User dropdown?  And then reference it (the User's Id) in the HTML to populate the dropdown?
 
The following is the S-Control function to pull the users and the HTML where I want to pull each User into my option value.

function getUserList()

{

var userList = sforce.connection.query("select Id, Name from User limit 10");

var userListRecords = userList.getArray("records");

}

 

<form action="">

<select name="user">

<option value="getUserList()"></option>

</select>

</form>

Greg HGreg H

This should help:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
 <title>Build Picklist</title>
<!-- AJAX Toolkit version 12.0 --><script src="/soap/ajax/12.0/connection.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
<!--
//initiates the page
function pageInit() {
 var userPicklist = getUserOptions(); //get picklist options for Users
 document.getElementById("UserPlaceholder").innerHTML = userPicklist; //put HTML on page
}

//returns HTML for a picklist of users
function getUserOptions() {
 var returnHTML = "<select id=\"User\" name=\"User\">"; //start HTML for picklist
 var sql = sforce.connection.query("SELECT Id, Name FROM User ORDER BY Name ASC LIMIT 10");
 returnHTML += "<option value=\"none\">- SELECT -</option>";
 if (sql.getBoolean("done")) { //if done
  var records = sql.getArray("records"); //get an array of records
  for (var a=0; a<records.length; a++) { //for all records in array
   returnHTML += "<option value=\""+records[a].Id+"\">"+records[a].Name+"</option>";
  }
 }
 returnHTML += "</select>";
 return returnHTML;
}
//-->
</script>
</head>
<body onLoad="pageInit();">
<table>
 <tr>
  <td style="font-weight: bold;">Picklist</td>
  <td id="UserPlaceholder"></td>
 </tr>
</table>
</body>
</html>

-greg

jyotijyoti

Thanks Greg; this worked to generate the User List.  However, is it possible to get the User Id of what has been selected so as to assign the User to set of records?

The following statements yield a null or objectError

var extUserId = document.getElementById("UserPlaceholder").getAttribute("value");

var extUserId = document.getElementById("UserPlaceholder").value;



Message Edited by jyoti on 02-14-2008 06:58 PM
Greg HGreg H
You need to pull the values from the picklist not the placeholder in my example.  The picklist (the select tag) has an Id of "User" so that is the one you should be referring too.
Code:
var userPicklist = document.getElementById("User");
var selectedUserValue = userPicklist.options[userPicklist.selectedIndex].value;

The "selectedUserValue" variable will contain the option selected by your user.
-greg