How to get javascript picture loader button to work in Skuid

  • 1
  • Question
  • Updated 4 years ago
I have a Salesforce app called Picture Uploader with a custom button that works just fine in the native Salesforce UI.  I can't seem to get working in Skuid.  The custom button is on the Contact object with the following OnClick JavaScript:


var untreatedUrl = "{!URLFOR($SControl.btydev__Picture_Upload_Processor, Contact.Id)}";
var retUrl = untreatedUrl.replace(/\//g, '%2F');
var retUrl = retUrl.replace(/\?/g, '%3F');
var retUrl = retUrl.replace(/&/g, '%26');
var fullUrl = "/p/attach/NoteAttach?pid={!Contact.Id}&retURL=" + retUrl;

//alert (fullUrl);

parent.window.location.href="/p/attach/NoteAttach?pid={!Contact.Id}&retURL=" + retUrl + '%26autoMapValues=1';


What I've done that isn't working:

  1. I've created an inline snippet with the above code.
  2. I've created a custom "run skuid snippet" button that points to the snippet.
I think the part that is not working are the Skuid-specific javascript references that should come first in the snippet before the snippet. 

I welcome your tips.

Thanks!
Krista
Photo of krista06880

krista06880

  • 816 Points 500 badge 2x thumb
  • Meh

Posted 4 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Try this. No javascript necessary.

<skuidpage unsavedchangeswarning="yes" showsidebar="true" showheader="true" tabtooverride="Task">
   <models>
      <model id="CurrentContact" limit="1" query="true" createrowifnonefound="false" sobject="Contact" doclone="" type="">
         <fields>
            <field id="Id"/>
            <field id="Name"/>
         </fields>
         <conditions>
            <condition type="param" value="Id" field="Id" state="" operator="=" enclosevalueinquotes="true" novaluebehavior=""/>
         </conditions>
         <actions/>
      </model>
   </models>
   <components>
      <pagetitle model="CurrentContact">
         <maintitle>
            <template>{{Name}}</template>
         </maintitle>
         <subtitle>
            <template>{{Model.label}}</template>
         </subtitle>
         <actions>
            <action type="redirect" label="Upload Pic" window="self" icon="ui-silk-picture-add" url="https://c.na17.visual.force.com/apex/fileupload?id={{{Id}}}&amp;returl={{{Id}}}"/>
         </actions>
      </pagetitle>
      <template multiple="false" model="CurrentContact" allowhtml="true">
         <contents>&lt;iframe src="https://c.na17.visual.force.com/apex/showPicture?id={{{Id}}}&amp;isdtp=nv" width="100%" height="600px" frameborder="false"&gt;&lt;/iframe&gt;
</contents>
      </template>
   </components>
   <resources>
      <labels/>
      <css/>
      <javascript/>
   </resources>
</skuidpage>
 
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Ok. I get the custom setting for the org instance. What I don't get is how to construct the URL with the "c" at the beginning without actually typing it in to the template.
Photo of krista06880

krista06880

  • 816 Points 500 badge 2x thumb
I have the same question re: how to render the "c" . . .
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
If nothing else, we could make a custom for this. Base URL prefix.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Sometimes I just fool around with the URL via javascript. This is a snippet that changes the iframe src when you click on the tab containing the iframe for the first time. You can really do anything with JS:

(function(skuid){    var $ = skuid.$;
    $(function(){
        $('#myTab').one('tabshow', function(params){
            console.log(params);
            var Id = skuid.$M('Opportunity').getFirstRow().Id;
            var sfInstance = skuid.$M('CustomSettings').getFirstRow() .Instance__c;
            var iframe = $("#springCM");
            url = 'https://c.' + sfInstance + '.visual.force.com/apex /SpringCM_Opportunity?id=' + Id + '&isdtp=mn';
            iframe.attr("src", url);
        });
    });
})(skuid);
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
If you're clicking on a button you can make the button call this snippet:

var params = arguments[0],	$ = skuid.$;
var Id = skuid.$M('Opportunity').getFirstRow().Id;
var sfInstance = skuid.$M('CustomSettings').getFirstRow().Instance__c;
url = 'https://c.' + sfInstance + '.visual.force.com/apex/Your_URL?id=' + Id;
window.location = url;