How can I change the "key" name from an action field in Zapier (Scripting) with the KEY_pre_write method? - scripting

I was wondering how I can change the key of an action field through scripting in Zapier. I know I need to use KEY_pre_write to change an element before I send the request but how can I call the specific action field and change the key name in something else?
Zapier scripting image
The key name is currently "type" but I want to change it for instance to "type1".
Thanks in advance.

Fixed it myself btw, maybe for someone who needs to know.
'use strict';
var Zap = {
CompanyAdd_pre_write: function(bundle) {
var actionfields = bundle.action_fields;
var stringify = JSON.stringify(actionfields);
var body = stringify.replace("type1", "type"); // renaming key
bundle.request.data = body;
console.log(actionfields);
return bundle.request;
}
};

David here, from the Zapier Platform team.
key is set by the key of the action itself. See here:
Those would be action_pre_write, broken_js_pre_write, etc. Feel free to tweak these for a private app, but note that it'll break any existing zaps that use that action.
​Let me know if you've got any other questions!

Related

How to add an User Content through Sensenet Client?

I want to add an User Content of Sensenet from a client which developed by .NET.
Please give me a solution.
Thanks so much.
You should be able to create users the same way as any other content, by providing the parent, the content type name and a few mandatory fields.
The example below assumes that you already initialized the client, you have the /Root/IMS/MyDomain/MyOrgUnit in your repo and there is no existing user there with the same name.
var user = Content.CreateNew("/Root/IMS/MyDomain/MyOrgUnit", "User", "johnsmith");
user["LoginName"] = "johnsmith"; // best practice: same as the content name in the line above
user["Password"] = "123456789";
user["FullName"] = "John Smith";
user["Email"] = "johnsmith#example.com"; // this has to be unique under the domain
user["Enabled"] = true; // to let the user actually log in
await user.SaveAsync();
Let us know if you encounter any errors.

How do you configure a client to auto-answer within vLine?

What is the correct method for setting a client to auto answer with the vLine API for WebRTC calls?
Looking at your comment, it looks like you have figured this out. But for completeness and for future reference I will go ahead and answer.
To auto answer a call, all you have to do is call MediaSession.start() when an incoming call comes in, instead of throwing a prompt to the user.
Here is an example snippet:
client.on('add:mediaSession', onAddMediaSession, self);
// Handle new media sessions
onAddMediaSession(event){
var mediaSession = event.target;
mediaSession.on('enterState:incoming', onIncoming, self);
},
// Handle new incoming calls and autoAccept
onIncoming(event){
var mediaSession = event.target;
// Auto Accept call instead of a prompt
mediaSession.start();
}
Note that you can do this in your code even if you are using the UI Widgets.

Angular dynamic factory

I'm trying to use a single controller to list multiple similar collections so I can call different templates with the same controller. In fact, right now I have 6 controllers for listing and another 6 for forms but they're all duplicates.
I've made a non-functional plunker just to show how I intend it to work. I've avoided declaring routeProviders because knowing it wouldn't work I tried to make it as straight to the point as I could.
http://plnkr.co/edit/d06PcrJS5newhrmNy6EJ?p=preview
I've seen on stackoverflow how to declare a class with a dynamic name:
var str = "MyClass";
var obj = new window[str];
But as I have not been able to find where it's stored I'm not able to retrieve it.
Does anyone have a hint on how to do this?
You can use Angular's injector to return the service instance you want. For example:
app.controller('NodeListCtrl', function($scope, $location, $injector) {
var modelName = $location.path().split("/")[1];
$scope.modelName = modelName.charAt(0).toUpperCase() + modelName.slice(1);
$scope.nodes = $injector.get($scope.modelName).query();
});
Note: Don't forget to add the $injector to the controller's function signature.
jsfiddle: http://jsfiddle.net/bmleite/Mvk2y/

What appropriate way to create and use class ? (example inside)

Now. I so confuse when use any classes. What is best practice approach to use them?
Example
I have a UserClass name User that have 2 attributes UserName and Password
when I use I will create new object like this
UserClass userObject = new UserClass();
this is my question that I so confuse to use
If i want to call Method name "Login" what is appropriate way to use them?
Between
1 Set Value to Attribute of Object Like this
userObject.UserName = "user";
userObject.Password = "password";
if (userObject.Login())
{
//Do Something After Login
}
else
{
//Show Something when Error
}
2 Send Value as parameter
if (userObject.Login("user","password"))
{
//Do Something After Login
}
else
{
//Show Something when Error
}
From above
What is appropriate approach to use and apply to any classes?
Thank you very much for your guidance _/\_
P.S I practice to be better Programmer
Use a property to store information that belongs to the object. (eg, a Username)
Use a parameter to pass information to a single method which doesn't have to do with the rest of the object.

Return Entire field from GetBestFragment in FastVectorHighlighter

In Highlighter.Net, we can use NullFragmenter to return the entire field content. Is there any way we can do this in FastVectorHighlighter.Net?
If you use SimpleFragListBuilder-fragmenter for FastVectorHighlighter then need to modify a public static properties of fragmenter to manage fragment size:
var fieldContent = "some data";
SimpleFragListBuilder.MARGIN = fieldContent.Length;
SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE = SimpleFragListBuilder.MARGIN*3;
var result = highlighter.GetBestFragment(.., fragCharSize: SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE);
(see source for details - 'Lucene.Net 3.0.3 SimpleFragListBuilder.cs' [http://lucenenet.apache.org/docs/3.0.3/dd/d38/_simple_frag_list_builder_8cs_source.html])
Isn't it an option to just use document.Get("field_name") and return the entire field content in such a way? You probably have you document somewhere in the context anyway (as you need doc id to GetBestFragment()), so why not just use it?
There is a patch for java FVH that claims to do this. I haven't personally tested it.
https://issues.apache.org/jira/browse/LUCENE-2464