• Angie
  • 0 Points
  • Member since 2006

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 4

Thank you for attending one of my hands-on sessions on  S-Controls.
I hope Dreamforce was a great experience for you.

I have set up this discussion for class members to post and answer questions you might have after Dreamforce.

Please add your question under this post and a class participant or myself will answer you.

I will monitor this post for 2 weeks after Dreamforce.

Thank you

Here is the source:

<!-- Answers this is the working scontrol for class -->
<!-- author Michael Fullmore Salesforce.com -->
<!-- version .1 8/21/2007 -->
<!-- version 1.0 8/28/2007 -->

 <!-- addes the salesforce.com css file (look and feel) -->
 <link href="/dCSS/Theme2/default/common.css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" type="text/css" />
 <!-- adding my own styles to this scontrol -->
 <style type="text/css">
    <!-- these two script tags add the salesforce.com AJAX API and are required to "talk to salesforce" -->
    <script type="text/javascript" src="/js/functions.js"></script>
    <script src="/soap/ajax/10.0/connection.js"></script>
    <!-- this script tag starts our code, you can have as many script tags in your file as needed. we only need 1 for this demo -->
    <script type="text/javascript">
    //create the oppty object
    var opp = {id:"{!Opportunity.Id}", stage:"{!Opportunity.StageName}", nextStep:"{!Opportunity.NextStep}", description:"{!Opportunity.Description}"};
 //create an array of stages that we want to lock
    var lockedStages = ["Perception Analysis","Proposal/Price Quote","Negotiation/Review"," Closed Won","Closed Lost"];
    //checking to see if the user has access or not
    function doesUserHaveAccess(){
     //this is the first AJAX call, nice! Bonus points, what is it doing—
     var user = sforce.connection.getUserInfo();
     //get the profile name
     var profileNameQuery = sforce.connection.query("select Name from Profile where Id = '" + user.profileId + "'");
     var profileNameRecords = profileNameQuery.getArray("records");
     var profileName = profileNameRecords[0].Name;
     //next check if the user is locked out of oppty
     if(profileName == 'System Administrator'){ //adding TEST to the system administrator string to test with sys admin

      //using URLFOR to "skip over the override the second time around.
      window.parent.location.href = "{!URLFOR($Action.Opportunity.Edit, Opportunity.Id,[retURL=URLFOR($Action.Opportunity.View, Opportunity.Id)],true)}";
      //if the user is not in the admin user group then we show the edit page for them. This page just gives us access to 3 fields on the opportunity
    function showPage(){
     document.getElementById('edit').style.display = 'block';
     document.getElementById('next').value = opp.nextStep;
     document.getElementById('des').value = opp.description;
    //custom edit screen button actions
    function saveEdit(){
     //create an opportunity object
     var o = new sforce.SObject("Opportunity");
     //fill the opportunity SObject with data
      o.Id = opp.id;
      o.NextStep = document.getElementById('next').value;
      o.Description = document.getElementById('des').value;
     //save the SObject to salesforce, using the AJAX Tool Kit
     var saveO = sforce.connection.update([o]);
      if(saveO[0].getBoolean("success") == false){
     //go back to the opportunity
     window.parent.location.href = "/" + opp.id;
    function cancelEdit(){
     window.parent.location.href = "/" + opp.id;
    //help error function
    function error(e){
     alert("There is an error\n\n" + e);
    //where the page starts it's loading
    function initPage(){
     var isLocked = false;
     //this function starts the process, every scontrol needs to start somewhere, and I like using initPage
     //first thing we need to do is check to see what stage the oppty is in.
     for(i=0; i<lockedStages.length; i++){
      if(opp.stage == lockedStages[i]){
       //if it's in a "locked" stage then we go and see if the user has access.
       isLocked = true;
   //if the oppty is not is the "locked" stages then put up the normal edit page
      window.parent.location.href = "{!URLFOR($Action.Opportunity.Edit, Opportunity.Id,[retURL=URLFOR($Action.Opportunity.View, Opportunity.Id)],true)}";     
**what's next–                      *
**Try adding a stage advancer, something that puts the opportunity in the next stage for the reps *
**Add your own fields                    *
**Display read only fields                   *
<body onload="initPage();" class="opportunity overviewPage">
 <div id="edit" class="edit">
  <div class=bPageTitle>
   <div class="ptBody secondaryPalette">
    <div class="content">
     <img class="pageTitleIcon" title="Opportunity" alt="Opportunity" src="/s.gif"/>
      <h1 class="pageType">Opportunity Edit (Custom)<span class="titleSeparatingColon">:</span></h1>
      <h2 class="pageDescription">{!Opportunity.Name}</h2>
  <div class="bPageBlock secondaryPalette">
   <div class="pbBody">
    <div class="pbSubsection">
     <p>This Opportunity is in a stage that is locked by your company. The only fields that you have access to are 
     Next Steps and Description. If you need to make edits to other fields please contact your Administrator. <br>Thank you.</p>
     <label for="next">Next Step:&nbsp;&nbsp;&nbsp;</label>
     <input type="text" id="next" size="80" />
     <label for="des">Description:</label>
     <textarea id="des" cols="60" rows="5"></textarea>
     <input type="button" id="btn1" value="Save" class="btn" onclick="saveEdit();" />
     <input type="button" id="btn2" value="Cancel" class="btn" onclick="cancelEdit();" />


Message Edited by mikef on 09-21-2007 11:59 AM

  • September 15, 2007
  • Like
  • 0
I would like to prevent standard users from editing 'Closed/Won' opportunities, based on either forecast category or the specific stage we use.
this way, once an opportunity is closed, only an admin or other role we specify can edit that opportunity. 
Does anyone know if this is possible, and how to do it?