Opensearch With Dynamic Object - object

I need to perform a global search by free text. The documents, though, have a property “payload” which is an object type and its content is dynamic. This means that is not deterministic.
Is there a way to make a global search that basically treats the payload as a string? Sadly, changing the schema is not an option.
For example this document:
{
description: 'This is an example',
payload: {
random_property: 'Hello world'
}
}
has to be found by typing: ‘Hello’ or ‘random_property’ or ‘this is an example’.

Our use case is in AWS; we stored new data directly from an event bus to opensearch and we didn't have control on data.
There is no way to convert an object to a string at the query time or to search free text within a nested object without specifying an exact path. At least, we haven't found any solution.
So we added a lambda between the event bus and opensearch for mapping new data where we can handle a new property "plain_payload" that convert the payload to a string.

Related

Netsuite Invalid API usage. You must use getValue to return the value set with setValue

So I have an odd issue, When I create a new transaction and save, this error in the title gets thrown. But when I edit this transaction after it was created, the getText does not throw this error. Is there something I'm doing wrong or something special needed to getText on a create new record? Here is my code. This is for the afterSubmit method on my User Event Script for Vendor Bill screen. I just noticed getValue does work on create, does not produce this error, just don't understand why? Is this the correct way to get the value on create? To use getValue and getText cannot be used on create? Only for edit?
if (scriptContext.type == scriptContext.UserEventType.CREATE ||
scriptContext.type == scriptContext.UserEventType.EDIT) {
// get bill to index
var Bill = scriptContext.newRecord;
// fails on this call below on create but works on edit
var refno = Bill.getText({ fieldId: 'tranid' });
}
This behavior is described in the API documentation here.
In dynamic mode, you can use getText() without limitation but, in standard mode, limitations exist. In standard mode, you can use this method only in the following cases:
You can use getText() on any field where the script has already used setText().
If you are loading or copying a record, you can use getText on any field except those where the script has already changed the value by using setValue().
Apparently the newRecord object falls under the second criteria. At this point, the object only has values set. tranid will have a value with the transaction's internal ID, but it won't have the transaction name stored. To get the text, you will have to use record.load() to get the full record, or use search.lookupFields() to get just the transaction name.

How to return an output from javascript function using invoke js in blueprism

I want to read multiple key-value pairs from a webpage and write it to a collection using blueprism.
I want to use javascript.
I am able to read text from webpage but couldnt understand how to write that data into blueprism data item or a collection.
Blue Prism provides no facility to return data directly from a JavaScript call back into the calling Object. Your best bet is to use a script that generates a hidden input element in the DOM and appends the data you want to exfiltrate:
var hiddenElement = document.querySelector('#bp-output');
if (typeof hiddenElement === 'undefined') {
hiddenElement = document.createElement('input');
hiddenElement.type = 'hidden';
hiddenElement.id = 'bp-output';
document.body.appendChild(hiddenElement);
}
hiddenElement.value = /* some functionality to set the value of the newly-created hidden element */;
You'll need to model this element in your object's application modeler, but it's fairly simple to do - you don't need to match on any attributes other than "ID" or "Web ID", and it's a match only to the string bp-output.
From there, you can use a typical Read stage to read the value out of the value attribute of your element.
For more complex data structures like Collections, you will have to utilize some serialization trickery to get to where you want to be. For example, if you're trying to read a table into a Collection via JavaScript, your /* functionality to set the value of the newly-created hidden element */ in the example above may need to leverage some code from this SO thread to serialize the table itself to a CSV string. Once you've read the string from the hidden element's value, you could use the CSV-related actions in the vendor-provided Utility - Strings VBO to serialize this to a proper Collection for your use in your Objects/Processes.

Parameterized query in Postgresql with a json array

I would like to invoke array_prepend into a json[] using a parameterized query. I am using pg-promise npm package but this uses the normal node-postgres adapter under the hood.
My query is:
db.query(`update ${schema}.chats set messages =
array_prepend('{"sender":"${sender}","tstamp":${lib.ustamp()},"body":$1}',messages) where chat_id = ${chat_id}`
, message));
Same with "$1".
It works with a non-parameterized query.
Above code produces :
{ [error: syntax error at or near "hiya"]
Main reason for this is to avoid sql injection (docs say that they escape adequately when using the parameterized queries).
There are 2 problems in your query.
The first one is that you are using ES6 template strings, while also using sql formatting with ${propName} syntax.
From the library's documentation:
Named Parameters are defined using syntax $*propName*, where * is any of the following open-close pairs: {}, (), [], <>, //, so you can use one to your liking, but remember that {} are also used for expressions within ES6 template strings.
So you either change from ES6 template strings to standard strings, or simply switch to a different variable syntax, like $/propName/ or $[propName], this way you will avoid the conflict.
The second problem is as I pointed earlier in the comments, when generating the proper SQL names, use what is documented as SQL Names.
Below is a cleaner approach to the query formatting:
db.query('update ${schema~}.chats set messages = array_prepend(${message}, messages) where chat_id = ${chatId}', {
schema: 'your schema name',
chatId: 'your chat id',
message: {
sender: 'set the sender here',
tstamp: 'set the time you need',
body: 'set the body as needed'
}
}
);
When in doubt about what kind of query you are trying to execute, the quickest way to peek at it is via pgp.as.format(query, values), which will give you the exact query string.
And if you still want to use ES6 template strings for something else, then you can change the string to:
`update $/schema~/.chats set messages = array_prepend($/message/, messages) where chat_id = $/chatId/`
That's only one example, the syntax is flexible. Just remember not to use ES6 template string formatting to inject values into queries, because ES6 templates have no knowledge about how to properly format JavaScript types to comply with PostgreSQL, only the library knows it.

CRM 2011 JavaScript How to access data stored in an entity passed from a lookup control?

As the question suggests, I need to find out how to access entity data that has been passed into a JavaScript function via a lookup.
JavaScript Code Follows:
// function to generate the correct Weighting Value when these parameters change
function TypeAffectedOrRegionAffected_OnChanged(ExecutionContext, Type, Region, Weighting, Potential) {
var type = Xrm.Page.data.entity.attributes.get(Type).getValue();
var region = Xrm.Page.data.entity.attributes.get(Region).getValue();
// if we have values for both fields
if (type != null && region != null) {
// create the weighting variable
var weighting = type[0].name.substring(4) + "-" + region;
// recreate the Weighting Value
Xrm.Page.data.entity.attributes.get(Weighting).setValue(weighting);
}
}
As you can see with the following line using the name operator I can access my Type entity's Type field.
// create the weighting variable
var weighting = type[0].name.substring(4) + "-" + region;
I am looking for a way now to access the values stored inside my type object. It has the following fields new_type, new_description, new_value and new_kind.
I guess I'm looking for something like this:
// use value of entity to assign to our form field
Xrm.Page.data.entity.attributes.get(Potential).setValue(type[0].getAttribute("new_value"));
Thanks in advance for any help.
Regards,
Comic
REST OData calls are definitely the way to go in this case. You already have the id, and you just need to retrieve some additional values. Here is a sample to get you started. The hardest part with working with Odata IMHO is creating the Request Url's. There are a couple tools, that you can find on codeplex, but my favorite, is actually to use LinqPad. Just connect to your Org Odata URL, and it'll retrieve all of your entities and allow you to write a LINQ statement that will generate the URL for you, which you can test right in the browser.
For your instance, it'll look something like this (it is case sensitive, so double check that if it doesn't work):
"OdataRestURL/TypeSet(guid'" + type[0].Id.replace(/{/gi, "").replace(/}/gi, "") + "'select=new_type,new_description,new_value,new_kind"
Replace OdataRestURL with whatever your odata rest endpoint is, and you should be all set.
Yes Guido Preite is right. You need to retrieve the entity by the id which come form the lookup by Rest Sync or Async. And then get Json object. However for make the object light which is returned, you can mention which fields to be backed as part of the Json. Now you can access those fields which you want.

Storage in LWUIT

Please can someone give me a small sample of how to use the Storage class in LWUIT? I have tried implementing by emulating the system used in the Recipe Hands-on-Lab, but my application does not need to have multiple objects, as it is within the sample.
Recipe sample allows user to add more and more samples, but all I want to do is add ONE entry of information.
Also how do I retrieve the info stored?
com.sun.lwuit.io.Storage.init("MobileApplication1");
if(com.sun.lwuit.io.Storage.isInitialized()) {
com.sun.lwuit.io.Storage.getInstance().writeObject("MobileApplication1","My first string");
String myStr = (String)com.sun.lwuit.io.Storage.getInstance().readObject("MobileApplication1");
System.out.println(myStr);
} else {
System.out.println("Storage not initialized");
}
The above code will create a storage of name 'MobileApplication1', add an object 'My first string' and reads the string.
You can use J2ME record store as well and your record store will always have only 1 record.

Resources