Twilio studio plus function, can't use string.split() - twilio

I can't split up a string using Functions. This is an SMS app in Studio:
User texts his full name to Twilio, I call a function and add the Liquid variable with their full name and send it to a Function where I want to return only the first name.
exports.handler = function(context, event, callback) {
var firstName = event.fullName.split(' ');
callback(null, firstName[0]);
};
error message:Cannot read property 'split' of undefined

First, your code for the function is fine, except that event.fullName is undefined because is not being passed from the Studio.
In Studio, add a fullName parameter to the function call. The value for the parameter is {{trigger.message.Body}} (to pass the incoming message text body to the function), then you will be able to access it in your function.
Note: In the "Function Parameters" section of the "RUN FUNCTION" widget there are two "Save" buttons, you will need to click them both, first the one for the parameters, then the (red) one for the widget.
Here is a screen capture which might help you

Related

Playwright: Two elements with the same name, how to fill the one that is visible?

I have an Ionic React app that uses react-router 5 to display various pages.
The app defaults to a login form, but if users go to the support page, there is a contact form.
I'm trying to test the contact form in Playwright with code like this:
await page.fill('input[name=mail]', 'playwright#example.com');
However, I'm getting an error:
=========================== logs ===========================
waiting for selector "input[name=mail]"
selector resolved to 2 elements. Proceeding with the first one.
selector resolved to hidden <input name="mail" type="email" placeholder="" autocorr…/>
elementHandle.fill("playwright#example.com")
waiting for element to be visible, enabled and editable
element is not visible - waiting...
The problem is that Playwright is seeing the first email address input on the login form, which is not visible, and then trying to fill that in instead of the visible email address input on the contact page.
Obviously, I never want to fill in an element that isn't visible, so how can I force playwright to only try to fill in visible elements?
You can use page.locator to check for visibility first and then fill in the value.
await page.locator('input[name=mail] >> visible=true').fill('playwright#example.com');
To make tests easier to write, wrap this in a helper function:
async fillFormElement(
inputType: 'input' | 'textarea',
name: string,
value: string,
) {
await this.page
.locator(`${inputType}[name=${name}] >> visible=true`)
.fill(value);
}
It can be done in this way, if you are trying to check is element visible. Even you have two same elements with one selector one hidden one visible.
const element = await page.waitForSelector(selector, {state:visible});
await element.fill(yourString);

What is val function and what does this ‴return $('#q').val();‴ mean in this code?

Is it like val function is predefined?
code:
selenium.open chrome url msn.com timeout 30000
list.create text aa result ♥list
selenium.callfunction search q by id functionname val parameters ♥list type jquery
selenium.runscript script ‴return $('#q').val();‴
dialog ♥result
val() is a method in jQuery that lets you set or get the value of a given HTML element (Documentation here). #q is the ID of the search field over at msn.com, so what that script does is it retrieves the value typed out in that field. Since it's usually empty when the site is just loaded up, you would get an empty dialog box when calling dialog ♥result.

NetSuite/Suitescript/Workflow: How do I open a URL from a field after clicking button?

I have a workflow that adds a button "Open Link" and a field on the record called "URL" that contains a hyperlink to an attachment in NetSuite. I want to add a workflow action script that opens this url in a different page. I have added the script and the workflow action to the workflow. My script:
function openURL() {
var url = nlapiGetFieldValue('custbody_url');
window.open(url);
}
I get this script error after clicking the button: "TypeError: Cannot find function open in object [object Object].
How can I change my script so it opens the URL in the field?
(This function works when I try it in the console)
Thanks!
Do you want it to work when the record is being viewed or edited? They have slightly different scripts. I'm going to assume you want the button to work when the record is being viewed, but I'll write it so it works even when the document is being edited as well.
The hard part about the way Netsuite has set it up is that it requires two scripts, a user event script, and a client script. The way #michoel suggests may work too... I've never inserted the script by text before personally though.
I'll try that sometime today perhaps.
Here's a user event you could use (haven't tested it myself though, so you should run it through a test before deploying it to everyone).
function userEvent_beforeLoad(type, form, request)
{
/*
Add the specified client script to the document that is being shown
It looks it up by id, so you'll want to make sure the id is correct
*/
form.setScript("customscript_my_client_script");
/*
Add a button to the page which calls the openURL() method from a client script
*/
form.addButton("custpage_open_url", "Open URL", "openURL()");
}
Use this as the Suitescript file for a User Event script. Set the Before Load function in the Script Page to userEvent_beforeLoad. Make sure to deploy it to the record you want it to run on.
Here's the client script to go with it.
function openURL()
{
/*
nlapiGetFieldValue() gets the url client side in a changeable field, which nlapiLookupField (which looks it up server side) can't do
if your url is hidden/unchanging or you only care about view mode, you can just get rid of the below and use nlapiLookupField() instead
*/
var url = nlapiGetFieldValue('custbody_url');
/*
nlapiGetFieldValue() doesn't work in view mode (it returns null), so we need to use nlapiLookupField() instead
if you only care about edit mode, you don't need to use nlapiLookupField so you can ignore this
*/
if(url == null)
{
var myType = nlapiGetRecordType();
var myId = nlapiGetRecordId();
url = nlapiLookupField(myType, myId,'custbody_url');
}
//opening up the url
window.open(url);
}
Add it as a Client Script, but don't make any deployments (the User Event Script will attach it to the form for you). Make sure this script has the id customscript_my_client_script (or whatever script id you used in the user event script in form.setScript()) or else this won't work.
Another thing to keep in mind is that each record can only have one script appended to it using form.setScript() (I think?) so you may want to title the user event script and client script something related to the form you are deploying it on. Using form.setScript is equivalent to setting the script value when you are in the Customize Form menu.
If you can get #michoel's answer working, that may end up being better because you're keeping the logic all in one script which (from my point of view) makes it easier to manage your Suitescripts.
The problem you are running into is that Workflow Action Scripts execute on the server side, so you are not able to perform client side actions like opening up a new tab. I would suggest using a User Event Script which can "inject" client code into the button onclick function.
function beforeLoad(type, form) {
var script = "window.open(nlapiGetFieldValue('custbody_url'))";
form.addButton('custpage_custom_button', 'Open URL', script);
}

Clojure and JavaFX 2.0 -- How to access element's ID from clojure callback function

Following the JavaFX Tutorial here: http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm, trying to make it run in Clojure. For now I'm just doing lein run after setting up :aot :all and stuff with (:gen-class) etc. It took a few days of figuring out, but now it seems to be mostly working.
In src/jfxtwo/ClojureExampleController.clj:
(defn -handleSubmitButtonAction [^ActionEvent event]
(let [actiontarget (Text.)]
(println "event button pressed")
(println "Event instance:" event)
(println "Event class:" (class event))
(.setText actiontarget "Sign in button pressed...")))
In resources/fxml_example.fxml:
<GridPane fx:controller= "jfxtwo.ClojureExampleController"
xmlns:fx= "http://javafx.com/fxml"
alignment= "center" hgap= "10" vgap= "10"
styleClass= "root" >
...
<Button text= "Sign In"
onAction= "#handleSubmitButtonAction" />
...
<Text fx:id= "actiontarget"
GridPane.columnIndex= "1" GridPane.rowIndex= "6" />
...
I have my clojure code able to read the fxml and css file to generate the proper GUI. When I press the button I can see the event handler being called, but I don't know how to access the Text I want to change, or the ActionEvent instance that is associated with the button press. I tried (println event) and (println (class event)) expecting to see something about an ActionEvent instance, but this only results in showing me that for whatever reason the callback function thinks the event is a ClojureExampleController, even though the type hint says it should be an ActionEvent:
event button pressed
Event instance: #<ClojureExampleController jfxtwo.ClojureExampleController#3e61061d>
Event class: jfxtwo.ClojureExampleController
The Java code to do this looks like this:
public class JFXAppSampleController {
#FXML private Text actiontarget;
#FXML protected void handleSubmitButtonAction(ActionEvent event) {
actiontarget.setText("Sign in button pressed");
}
}
Clearle the #FXML annotation is doing the magic here. What's going on, and how do I make this work in Clojure?
Also, is there a way to bind the button press to the text change directly in the FXML so I don't really have to handle a gui->gui change in the code-behind, and instead only deal with the logic associated with the button press? I'm guessing yes, but I haven't gotten to that point in the tutorial.
thanks!
You need an explicit this argument in your handler:
(defn -handleSubmitButtonAction [this ^ActionEvent event]
...)
Perhaps a more accurate way of putting this is that event is the this argument in your handler as exhibited in the question text and you need to add a second argument to accept the event in and move the type hint to it (and probably rename the first argument to this for readability).
Given the fact that your code gets called at all, it would seem that JavaFX is happy to call a handler without passing it the event at all if it doesn't care about it (as evidenced by not having a formal parameter corresponding to it).
The type hint's only purpose is to allow the Clojure compiler to avoid emitting reflective code when ActionEvent methods are called on event. This will not prevent passing an object of a different type to the function.

JQuery passing arguments for On Change for an item added to DOM via AJAX

I have multiple HTML fragments that are inserted into my DOM as the result of AJAX call-backs.
Each of these fragments will contain a text box whose class is "quantity".
What I want to do is to create an "on change" event handler that fires whenever one of these textbox's text value is changed. However, when that event is fired/handled, I need to know WHICH specific textbox was updated.
Okay, using jQuery, I have the following that fires in my "Lists.initHandlers" method:
$(document).on('change', $('#divABC').find(".quantity"), List.quantityChanged);
And my "List.quantityChanged" event handler happily fires when I update the quanity.
The problem is that when I reference "this" within the event handler, I get the whole document, and not the element that triggered the event.
I have tried to capture the element using syntax similar to:
$(document).on('change', $('#divABC').find(".quantity"), {ctrl: this}, List.quantityChanged);
but when I attempt this, the handler is never fired (even when I change the signature to expect an argument).
Any guidance here would be most appreciated.
Thanks
Griff
Try this:
$('.quantity').live('change', function(){
alert('New value: ' + $(this).val());
});
Pass this to your function:
$(document).on('change', $('#divABC').find(".quantity"), function () {
List.quantityChanged(this);
});

Resources