0

I'm trying to open an order as a Subtab in Service Console from a sidebar component based on the order number entered in a text box by the user.

I am not receiving any error yet this doesn't work. If anyone could look at my code, to would be much appreciated.

<apex:page controller="OrderSearchController" docType="html-5.0">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>        
   <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"></link>
   <apex:includeScript value="/support/console/22.0/integration.js"/>

         <apex:form>
          <form role="form"> 
                <div class="form-group">
                    <label for="ordernumber">Order Number</label>
                    <input id="onumber" class="form-control" type="string" value="{!ordernumber}" ></input>
                </div>
                <div class="form-group">
                    <label for="itemnumber">Item Number</label>
                    <input id="inumber" class="form-control" type="string" value="{!itemnumber}"></input>
                </div>
                <div class="form-group">
                    <label for="ponumber">PO Number</label>
                    <input id="pnumber" class="form-control" type="number"></input>
                </div>
                <div class="form-group">
                    <label for="connumber">Confirmation Number</label>
                    <input id="cnumber" class="form-control" type="number"></input>
                </div>
                <div class="form-group">
                    <label for="datefrom">Order Date From</label>
                    <input id="orderdate" class="form-control" type="date"></input>
                </div>
                <div class="form-group">
                    <label for="datefrom">Order Date To</label>
                    <input id="dateto" class="form-control" type="date"></input>
                </div>

                <div id="sbutton">                        
                    <apex:commandButton styleclass="btn btn-warning" id="next" value="Submit" onclick="getRemoteAccount()"/>            
                </div>


          </form>
          </apex:form>


              <script type="text/javascript">
                function getRemoteAccount() {
                    alert("hello");
                    var ordernumber = document.getElementById('onumber').value;

                Visualforce.remoting.Manager.invokeAction(
                    '{!$RemoteAction.OrderSearchController.Submit}',
                        ordernumber, 
                    function(result, event){
                        testOpenSubtab(result)
                    {escape: true}
                  }  
                );
            } 





                function testOpenSubtab(r) {
                    //First find the ID of the primary tab to put the new subtab in
                    sforce.console.getEnclosingPrimaryTabId(openSubtab,r);
                }

                var openSubtab = function openSubtab(result,r) {
                    //Now that we have the primary tab ID, we can open a new subtab in it
                    var primaryTabId = result.id;
                    sforce.console.openSubtab(primaryTabId , r, false, 
                        'salesforce', null, openSuccess, 'salesforceSubtab');
                };

                var openSuccess = function openSuccess(result) {
                    //Report whether we succeeded in opening the subtab
                    if (result.success == true) {
                        alert('subtab successfully opened');
                    } else {
                        alert('subtab cannot be opened');
                    }
                };



          </script>



</apex:page>

Controller:

  global with sharing class OrderSearchController{

    public String ordernumber {get;set;}
    public String itemnumber {get;set;}
    public static List <Order> orders {get;set;}
    public static String oId {get;set;}  
    public static String finalLink {get;set;}

    public OrderSearchController(){

    }

    @RemoteAction
    global static String Submit(String ordernumber) {
        orders = [Select Id From Order Where SAP_Order_Number__c = :ordernumber Limit 1];  
        oid = orders[0].Id;
        finalLink = 'https://na17.salesforce.com/' + oid;
        return finalLink;
     }

    } 

1 Answer 1

2

The only thing I can see here is you call you remote action via an apex:commandbutton with the onclick tag so the system submits the form without executing your code.

Options :

  • Add return false in your onclick

        onclick="getRemoteAccount();return false;"
    
  • Use a simple html button instead
1
  • No worries @user5428. If you could mark the answer, that will help other people. Cheers!
    – brovasi
    Aug 27, 2014 at 6:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .