run action sequence from snippet

  • 2
  • Question
  • Updated 5 months ago
  • Answered
How?
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,426 Points 20k badge 2x thumb

Posted 1 year ago

  • 2
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,426 Points 20k badge 2x thumb
Two steps closer. Been able to get the object for the sequence I want and run it.

var queryAllRecords = skuid.actionSequences.getByName('Query All Records');

queryAllRecords.run();

How can I set the inputs for the sequence. I assume I have to provide the parameters in the run function. Just dunno what format it needs.
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,426 Points 20k badge 2x thumb
Pretty sure it's g in the function.

Photo of Matt Davis

Matt Davis, Employee

  • 1,270 Points 1k badge 2x thumb
Any reason against using the skuid.events to publish an event that'll kick off the action sequence? Via skuid.events it would just look something like this
var obj = {dollars: "1500", pennies:'abc'};
skuid.events.publish('hellovent',obj);
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,426 Points 20k badge 2x thumb
Hmmm ... seems intriguing. I'd like to get the best of all options where it's an Reusable Action Sequence for declarative reasons and an Event-triggered Sequence for javascript reasons.
Photo of Matt Davis

Matt Davis, Employee

  • 1,270 Points 1k badge 2x thumb
Yeah it's works out well, and just to clarify the dollars/pennies were Inputs the action sequence was expecting. Just realized that I gave zero explanation for why that extra line was there...
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,426 Points 20k badge 2x thumb
Finally got back to this and it works beautifully.  Thanks.
Photo of Matt Davis

Matt Davis, Employee

  • 1,270 Points 1k badge 2x thumb
glad to hear it worked out!
Photo of Chandra V

Chandra V, Champion

  • 7,650 Points 5k badge 2x thumb
We are using this:

        skuid.actionSequences.getByName("MyActionSequence").run()

            .then(function(newContext) {

 

                //Actions after calling action here

 

                console.log("outputs from Data Source Action", newContext.$PreviousAction.result);

                });


To pass inputs, we are setting variables in the snippet on a UI model and then merge the values into your action.

For example, we use this heavily to create custom chatter posts.  So we have  'PostChatter' action sequence.  I've got a UI model that captures "Message" and Parent" (set via snippet) and then calls the action sequence to create the chatter post.
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,426 Points 20k badge 2x thumb
Yup. I've had to resort to using a UI only model as well. Rather not, but alas I could not find a way to set inputs for the action sequence.
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,840 Points 5k badge 2x thumb
Thanks for sharing your ideas, Matt and Chandra. Glad you have a way to get it working, Pat! Will check in with our product management team about an easier way to do this ... 

Thanks!
Karen
Photo of Zach McElrath

Zach McElrath, Employee

  • 53,784 Points 50k badge 2x thumb
Official Response
Pat / Chandra,

As of the Millau U2 Release, we adjusted the syntax of the Action Sequences run() function to have named Action Framework Inputs be the first argument that run() accepts. So as of 11.2.x release, the recommended way to do this is the following:

var namedInputs = {
    "ZipCode": "37408",
    "TotalPounds": 4.5
};
skuid.actionSequences.getByName("GetShippingRate").run(namedInputs);

This is the supported way to invoke Action Sequences from JavaScript by name, passing in named inputs.
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,426 Points 20k badge 2x thumb
Perfect. Just updated my code. Thx
Photo of Fernando Ramirez

Fernando Ramirez

  • 212 Points 100 badge 2x thumb
Is this compatible/usable to submit an Apex Class?

I am trying to pass Inputs values to a Action Sequence from this snippet script:


var namedInputs = {
    "BaseModelName" : "",
    "ButtonName": "TestSubmit",
    "LayoutObjectName" : "",
    "LayoutObjectType" : "",
    "Message" : "This is a test from Skuid page : Snippet",
    "PageName": "Logging_Message__Test",
    "PopupName" : "",
    "SnippetName" : "newSnippet"
};

skuid.actionSequences.getByName("WriteLogSequence").run(namedInputs);


The Action Sequence submits an Apex class (Invocable Method) matching the variables to the parameters on the method. 

Issue is, the apex method is submitted, but no values passed from the Snippet.

IF I set some default values on the Action Sequence , then apex method runs fine.

Any idea?

EDIT:   Skuid  version 11.2.6 
(Edited)
Photo of Jayesh Bhatnagar

Jayesh Bhatnagar

  • 636 Points 500 badge 2x thumb
Any updates on this? We are not able to pass parameters to action sequence as indicated in above scenario. This does not work in 11.2.9 also.
Photo of Zach McElrath

Zach McElrath, Employee

  • 53,784 Points 50k badge 2x thumb
Jayesh, just to confirm, you have defined a named Input for each of the parameters you are trying to pass in via the JavaScript snippet? 

i.e. if you are trying to do this:

var namedInputs = {
    "hello" : "world",
    "exchangeRate": 1.04,
    "Pizza" : "Mushroom",
};
skuid.actionSequences.getByName("WriteLogSequence").run(namedInputs);

you would need to have declared these Inputs in your Action Sequence:

Photo of Jayesh Bhatnagar

Jayesh Bhatnagar

  • 636 Points 500 badge 2x thumb
@Zach sorry for the delayed response on this but this is still an issue for us. We do have the inputs setup on the action sequence. We are also passing in the namedInputs similar to the snippet example you provided.
Photo of Zach McElrath

Zach McElrath, Employee

  • 53,784 Points 50k badge 2x thumb
Hi Jayesh, I will email you directly to try to setup a web meeting to walk through this. 
Photo of Jayesh Bhatnagar

Jayesh Bhatnagar

  • 636 Points 500 badge 2x thumb
Zach was kind enough to work with me on this issue. The critical piece of information I was missing was the syntax to refer to the the action sequence inputs in the actions tab section. So for the above e.g. you would refer to the input in the actions section as {{$Input.hello}}
Photo of Luzie Baumgart

Luzie Baumgart, Official Rep

  • 3,510 Points 3k badge 2x thumb
Jayesh, thank you for the feedback, happy to hear that you and Zach could solve the issue!
Photo of Jer Carpenter

Jer Carpenter, Employee

  • 160 Points 100 badge 2x thumb
As of Skuid 12, .run() supports 2 parameters as follows:
skuid.actionSequences.getByName("WriteLogSequence").run(namedInputs, context);
where context looks like:
{ row: {}, model: {} }
Prior to this, both namedInputs and context were expected as the 1st parameter, so this is a change in Skuid 12 (possibly dates back to 11.2, actually).  If you have a context object in your JS, this will allow your called action sequence to be context aware.
(Edited)