Button to redirect to another page with parameters based on field values

  • 2
  • Question
  • Updated 6 years ago
  • Answered
To generate a DrawLoop document, I want to make a button that does this:
Where "ID" is the SF record ID of a record currently in use by my model.

When I tried to put this into a simple redirect button (without the "window.open") it interpreted my curly braces as literals. Is there a different syntax I would use to it that way?

Alternatively, I should be able to make this out of a snippet, but what is the syntax to retrieve specific field values of specific records in the models on my page (and the Session ID) in the javascript?
Photo of Peter Bender

Peter Bender, Champion

  • 6,296 Points 5k badge 2x thumb

Posted 6 years ago

  • 2
Photo of Zach McElrath

Zach McElrath, Employee

  • 51,638 Points 50k badge 2x thumb
Official Response
You'll need to tell Skuid to perform a merge on this URL in the context of your record.

There are several Skuid API methods you can use to do this, but if you have a Model and Row in context, as you will when making a custom snippet to use in a PageTitle button, you should use the "mergeRow" API method of the Skuid Model object, which takes as its arguments a row to use as the "context" for the merge, and then a merge template, such as your URL.

Here is the signature for the mergeRow method:

Model.prototype.mergeRow = function(row,template,options) {}

And here is an example that should work for your scenario:

// A PageTitle button
// should provide these variables in its arguments
// when you're using a custom snippet

var params = arguments[0],
model = params.model,
row = params.row;

var url = "/apex/loop__looplus?eid={{Id}}&sessionId={{$Api.Session_Id}}&autorun=true";
var merges = skuid.$('<div>').append(model.mergeRow(row,url));

Photo of Peter Bender

Peter Bender, Champion

  • 6,296 Points 5k badge 2x thumb
Thanks for the help. So, the code that you provided that is what the snippet should look like, and just referencing that snippet from a page title button should automatically provide the right parameters to the snippet, is that right?

When I do this, I get a page that only shows the following error message:The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.
The URL provides a clue, probably: https://skuid.na14.visual.force.com/apex/[object%20Object]
Photo of Zach McElrath

Zach McElrath, Employee

  • 51,588 Points 50k badge 2x thumb
Peter, I have updated my answer --- the last two lines of the Snippet need to be changed. The "mergeRow" method actually returns a result that is suitable for inclusion in the page's DOM, not a plain text string. So, after appending this content to a temporary DIV, you can grab the internal text contents of the DIV, and this is a string, suitable for inclusion in a URL.