Problem with sforce.apex.execute

  • 2
  • Problem
  • Updated 2 years ago
  • Solved
I'm converting the following onclick javascript to a Skuid javascript snippet, and am getting an "Uncaught TypeError" at execute. Any ideas on how to resolve this?

Salesforce Button:

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
var originalValue = this.value;
this.value = "Processing...";
var request = new Object();
request.Action = "view";
request.AttachmentId = "{!ATT_EXP__Attachment__c.Id }";
request.UserAgent = navigator.userAgent;
debugger;
var attachmentURL = sforce.apex.execute("ATT_EXP.AttachmentsController","GetViewSignature",{JSONrequest:JSON.stringify(request)});
this.value = originalValue;
window.open(attachmentURL);

Skuid Snippet:

var params = arguments[0],
	$ = skuid.$;
	models = skuid.model.map();
var attachmentId = models.Attachment_view.getFirstRow().Id;

var originalValue = this.value;
    this.value = "Processing...";
var request = new Object();
    request.Action = "view";
    request.AttachmentId = attachmentId ;
    request.UserAgent = navigator.userAgent;

var attachmentURL = sforce.apex.execute("ATT_EXP.AttachmentsController","GetViewSignature",{JSONrequest: JSON.stringify(request)});

this.value = originalValue;
window.open(attachmentURL);
Photo of Brayden Smith

Brayden Smith

  • 1,078 Points 1k badge 2x thumb

Posted 2 years ago

  • 2
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Brayden,

Where does 'navigator.userAgent' originate?  I don't see it defined in your script.

Thanks,

Bill
Photo of Brayden Smith

Brayden Smith

  • 1,078 Points 1k badge 2x thumb
Its defined by the browser. When I use console log to view the "request" variable, it appears correctly.
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Brayden,

Do you have a reference on the Skuid page to the ajax resource?

/soap/ajax/29.0/apex.js



Thanks,

Bill
Photo of Brayden Smith

Brayden Smith

  • 1,078 Points 1k badge 2x thumb
That's what it was! Thanks for helping me resolve this.

-Brayden