Is it possible to add a Custom Salesforce Button from an installed package to a skuid page? The but

Jake MillerJake Miller Member
edited March 2018 in Questions
Is it possible to add a Custom Salesforce Button from an installed package to a skuid page?  The button is an Execute JavaScript

Comments

  • edited March 2018
    Jake,

    Add a Button Set or Page Title component to your page.  Then add a button and select 'Custom: SF Button/Link' as the Button Type.  Your button should show in the Custom Button / Link Name option.

    Thanks,

    Bill
  • Jake MillerJake Miller Member
    edited March 2018
    Thanks Bill!  Looks like no OnClick JavaScript buttons are available with the above steps, it is a button of Type = List Button with Content Source = OnClick JavaScript.  It is a button that is from an installed package we purchased.
  • edited March 2018
    Jake,

    Skuid would not be able to run the buttons with OnClick JavaScript.  Most of these types of buttons only have a little bit of 'code' in them.  Much of this code isn't needed with Skuid.  You can 'rebuild' the button using Skuid actions most of the time.

    If you need code, the script usually 'translates' to Skuid pretty well.  Here is a link where Rob Hatch rebuilt an OnClick JavaScript as a snippet:

    https://community.skuid.com/skuid/topics/could-any-one-help-me-to-change-salesforce-javascript-execu...

    Would you post the JavaScript from the button.  I can take a look.

    Thanks,

    Bill
  • Rob HatchRob Hatch Skuad ✭✭
    edited March 2018
    Thanks for the shout out Bill.. 
  • Jake MillerJake Miller Member
    edited March 2018
    Thanks bill, I'll post JavaScript in below comment.
  • Jake MillerJake Miller Member
    edited March 2018
    // create the form. Set it up to POST the transaction  f = document.createElement("form");  f.action="https://toutapp.com/components/add_to...";  f.method = "post";  f.target = "_blank";   // add the session id as a parameter  i = document.createElement("input");  i.id = "session";  i.name = "session";  i.type = "hidden";  i.value = "{!API.Session_ID}";  f.appendChild(i);   // add the server location as a parameter  i = document.createElement("input");  i.id = "server";  i.name = "server";  i.type = "hidden";  i.value = "{!API.Partner_Server_URL_90}";  f.appendChild(i);   // Get the Object IDs that were checked  idArray = {!GETRECORDIDS($ObjectType.Contact)};   if(idArray.length > 0) {  // add the idArray as a parameter  i = document.createElement("input");  i.id = "ids";  i.name = "ids";  i.type = "hidden";  i.value = idArray;  f.appendChild(i);   // add the object type  i = document.createElement("input");  i.id = "object_type";  i.name = "object_type";  i.type = "hidden";  i.value = "Contact";  f.appendChild(i);   // add the form to the document.  document.body.appendChild(f);  var w = window.open("", "MySubWindow", "height=435,width=648");  f.target = "MySubWindow";  // submit the form  f.submit();  } else {  alert("Please select at least one Contact to add to a Tout Campaign.");  }
  • edited March 2018
    Jake,

    Will you add this button to a page with a table of Contacts?  It looks like the code was setup to use contacts 'selected' in a table (what Skuid calls a Mass Action).  The reason for asking is that it changes how you would get the Contact Ids to put into the form submit.

    The good news is that this script only needs a few changes.

    Thanks,

    Bill
  • Jake MillerJake Miller Member
    edited March 2018
    Correct, it is a table of Contacts with fields from Accounts as well.  So 3 models: Contacts, Accounts, User (to pull in Contacts/Accounts they own)
  • edited March 2018
    Jake,

    This is a sample page with the script included as a mass action on the table.  You will need to find the DOM element 'Id' of your table.  I changed mine to 'contactTable'.  

    Thanks,

    Bill
    <skuidpage unsavedchangeswarning="yes" personalizationmode="server" useviewportmeta="true" showsidebar="true" showheader="true" tabtooverride="Contact">
        <models>
            <model id="Contact" limit="100" query="true" createrowifnonefound="false" datasource="salesforce" sobject="Contact">
                <fields>
                    <field id="FirstName"/>
                    <field id="LastName"/>
                    <field id="CreatedDate"/>
                    <field id="Id"/>
                </fields>
                <conditions/>
                <actions/>
            </model>
        </models>
        <components>
            <pagetitle model="Contact" uniqueid="sk-lNF-199">
                <maintitle>
                    <template>{{Model.labelPlural}}</template>
                </maintitle>
                <subtitle>
                    <template>Home</template>
                </subtitle>
                <actions>
                    <action type="savecancel" uniqueid="sk-lNF-197"/>
                </actions>
            </pagetitle>
            <skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Contact" mode="read" allowcolumnreordering="true" uniqueid="contactTable">
                <fields>
                    <field id="FirstName" hideable="true" allowordering="true" uniqueid="fi-lN9-939"/>
                    <field id="LastName" hideable="true" allowordering="true" uniqueid="fi-lN9-940"/>
                    <field id="CreatedDate" hideable="true" allowordering="true" uniqueid="fi-lN9-941"/>
                </fields>
                <rowactions/>
                <massactions usefirstitemasdefault="true">
                    <action type="multi" label="Send to Toutapp" icon="sk-icon-import">
                        <actions>
                            <action type="custom" snippet="openToutapp"/>
                        </actions>
                    </action>
                </massactions>
                <views>
                    <view type="standard"/>
                </views>
                <searchfields/>
            </skootable>
        </components>
        <resources>
            <labels/>
            <css/>
            <javascript>
                <jsitem location="inlinesnippet" name="openToutapp" cachelocation="false">var params = arguments[0],
    $ = skuid.$;
    var sessionid = sforce.connection.sessionId;
    var partnerurl = sforce.connection.partnerServerUrls[9];
    console.log('sessionid');
    console.log(sessionid);
    console.log('partnerurl');
    console.log(partnerurl);
    var selected = skuid.component.getById("contactTable");
    var items = selected.list.getSelectedItems();
    console.log("items");
    console.log(items);
    // create the form. Set it up to POST the transaction 
    f = document.createElement("form"); 
    f.action="https://toutapp.com/components/add_to_campaign"
    f.method = "post"; 
    f.target = "_blank"; 
    // add the session id as a parameter 
    i = document.createElement("input"); 
    i.id = "session"; 
    i.name = "session"; 
    i.type = "hidden"; 
    i.value = sessionid; 
    f.appendChild(i); 
    // add the server location as a parameter 
    i = document.createElement("input"); 
    i.id = "server"; 
    i.name = "server"; 
    i.type = "hidden"; 
    i.value = partnerurl; 
    f.appendChild(i); 
    // Get the Object IDs that were checked 
    //idArray = {!GETRECORDIDS($ObjectType.Contact)}; 
    var idArray=[];
    for (var i=0; i &lt; items.length; i++) {
            idArray.push(items[i].row.Id);
    }
    console.log('idArray');
    console.log(idArray);
    if(idArray.length &gt; 0) { 
        // add the idArray as a parameter 
        i = document.createElement("input"); 
        i.id = "ids"; 
        i.name = "ids"; 
        i.type = "hidden"; 
        i.value = idArray; 
        f.appendChild(i); 
        
        // add the object type 
        i = document.createElement("input"); 
        i.id = "object_type"; 
        i.name = "object_type"; 
        i.type = "hidden"; 
        i.value = "Contact"; 
        f.appendChild(i); 
        
        // add the form to the document. 
        document.body.appendChild(f); 
        var w = window.open("", "MySubWindow", "height=435,width=648"); 
        f.target = "MySubWindow"; 
        // submit the form 
        f.submit(); 
    } else { 
        alert("Please select at least one Contact to add to a Tout Campaign."); 
    }</jsitem>
            </javascript>
            <actionsequences uniqueid="sk-lNF-248"/>
        </resources>
        <styles>
            <styleitem type="background" bgtype="none"/>
        </styles>
    </skuidpage>
Sign In or Register to comment.