Worklight WL.JSONStore Replace Doc failed - ibm-mobilefirst

I have initialize a collection. In that i have a single doc which holds UserPreferences. I an trying to updated few fields of this doc. But fails with errorCallback.
var dataToUpdate = {
userPreferencesID:1,
firstname:'Test Name',
lastName: 'Test Name 2'};
WL.JSONStore.get(tableName).replace(dataToUpdate).then(successCallback).fail(errorCallback);
If some forum i could see the syntax
WL.JSONStore.get(tableName).replace(query, option).then(successCallback).fail(errorCallback);
Which one is correct. I tried both, but failed to update the record.
IBM Worklight Version 6.1.0.2
Thank in advance.

The replace API takes a JSONStore document as the first parameter. For example:
{_id: 1, json: {userPreferencesID: 1, firstname: 'Test Name', lastName: 'Test Name 2'}}
Notice the _id and json keys. You're not passing a document as the first parameter.
Here's the API documentation for the replace API in Worklight v6.1.
You get JSONStore documents when you use, for example, the findAll API:
WL.JSONStore.get('collection').findAll()
.then(function (jsonstoreDocuments) {
// [{_id: 1, json: {name: 'carlitos', age: 99}}]
});
The example above presumes the JSONStore collection is not empty, if it's empty you'll get an empty array back (i.e. []).

Related

Mark a search unrestricted in suitescript 2.0

I am using a restlet to check whether a contact exist in netsuite or not. I am calling this restlet from an external environment. The problem I'm facing is the search should be marked unrestricted in order to get results otherwise its returning nothing. How should I mark the search unrestricted? This is my code
var result = search.create({
type : record.Type.CONTACT,
filters:['email','IS',contact_mail],
ispublic : true,
unrestricted: true,
columns: ['email']
}).run().getRange({
start: 0,
end: 1
});
Can someone help me with this!
You can create the contact saved search in the UI without any filters and mark it as unrestricted.
In your script, load the search with search.load, and then add the the email filter to the search before running it.
var searchObj = search.load({
type: record.Type.CONTACT,
id: customsearch_contact_search
});
searchObj.filters.push(['email','IS',contact_mail]);
var result = searchObj.run().getRange({start:0, end:1});

Is it possible to query document schema metadata in Sanity/GROQ?

I have a simple singleton document schema defined in my Sanity/NextJS project, to model my "Colophon" page (richText is a custom block field type):
export default {
title: 'Colophon',
name: 'colophon',
type: 'document',
__experimental_actions: ['update', 'publish'],
fields: [
{
title: 'Body',
name: 'body',
type: 'richText',
validation: Rule => Rule.required(),
},
],
};
I retrieve this document with a simple query in my NextJS application:
export async function getStaticProps() {
const colophon = await client.fetch(`
*[_type == "colophon"][0]
`);
// ...
};
Is it possible to write a GROQ query to retrieve the meta title defined in the schema, i.e. Colophon? Although this is a singleton document, I would like to avoid repeating this string in my project if possible. At the moment, I can only see the fields on the document in my results, i.e. body.
Thanks for reading!
No, I don't believe there is.
As far as I understand what you're after; The schema is defined in the studio-instance and not the datastore. Those two are not hard coupled. I have several studio-instances with small variations on the schemas using one single project/datastore. The API you query to get data does not care which studio and schema was used and cant answer for the actual schema details.

Setting custom field values on a card with the Trello API

I am trying to use the new Custom Fields methods of the Trello API to set the value of a custom field on a card.
I've created a custom field of type number. When I make a GET request for the custom field by it's id, it returns this custom field object:
{
"id":"5ab13cdb8acaabe576xxxxx",
"idModel":"54ccee71855b401132xxxxx",
"modelType":"board",
"fieldGroup":"837a643fd25acc835affc227xxxxxxxxxxxxxxxxxxxx",
"name":"Test Number Field",
"pos":16384,
"type":"number"
}
Then when I create a new card in the Trello UI (but do not type in a value in the Test Number Field box) and then GET that card using the customFieldItems=true (as documented here), it returns this card object (irrelevant fields removed):
{
"id": "5ab56e6b62abac194d9xxxxx",
"name": "test1",
"customFieldItems": []
}
Note that since I did not type anything into the Test Number Field box in the UI, the customFieldItems property contains an empty array.
Then if I type in the number 1 in the Test Number Field box in the UI and GET the card again, it returns this (irrelevant fields removed):
{
"id": "5ab56e6b62abac194d9xxxxx",
"name": "test1",
"customFieldItems":
[
{
"id": "5ab570c5b43ed17b2dxxxxx",
"value": {
"number": "1"
},
"idCustomField": "5ab13cdb8acaabe5764xxxxx",
"idModel": "5ab56e6b62abac194d9xxxxx",
"modelType": "card"
}
]
}
I want to be able to set the value of this custom field via API.
When I go to the API documentation for "Setting, updating, and removing the value for a Custom Field on a card," (here) I plug in the following information:
Query Auth
key: (our valid/working Trello API key)
token: (our valid/working Trello API token)
PATH PARAMS
idCard: (ID of the card that the Custom Field value should be set/updated for) 5ab56e6b62abac194d9xxxxx
idCustomField (ID of the Custom Field on the card.): 5ab570c5b43ed17b2dxxxxx
QUERY PARAMS
idCustomField (ID of the Custom Field to which the item belongs.): 5ab13cdb8acaabe576xxxxx
modelType (This should always be card.): card
value (An object containing the key and value to set for the card's Custom Field value. The key used to set the value should match the type of Custom Field defined.): {"number": 2}
When I click Try It, I get the response: 400 Bad Request "Invalid custom field item value."
I've tried the following things:
Switching the two idCustomField values (it's confusing that both the path parameter and query parameter have the same name, implying that they are meant to accept the same value, but then they have different descriptions, and the descriptions are vague/confusing).
Setting both idCustomField values to the same thing (for both of the possible IDs)
Setting the value to 2, {"number": "2"}, {number: 2}, {number: "2"} and more.
No matter what I try, I always get "Invalid custom field item value." This behaves the same way whether the card has a value in the custom field or not.
I'm pretty sure that the idCustomField in the path params is being accepted, because when I change one character, it gives me this error instead: "invalid value for idCustomField".
So I don't know if the "Invalid custom field item value." is referring to the query param idCustomField* or the value.
I also don't know if it makes a difference whether or not the card has an existing value in the custom field, but I want to be able to set the value of this custom field regardless of whether or not it currently has a value in the field.
The live example (using XMLHttpRequest) on the Trello documentation page is wrong. You should use the next example using fetch.
var url = "https://api.trello.com/1/cards/{idCard}/customField/{idCustomField}/item?token={yourToken}&key={yourKey}";
var data = {value: { number: "42" }};
fetch(url, { body: JSON.stringify(data), method: 'PUT', headers: {'content-type': 'application/json'}})
.then((resp) => resp.json())
.then((data) => console.log(JSON.stringify(data, null, 2)))
.catch((err) => console.log(JSON.stringify(err, null, 2)))
This example works. And after trying this, I modified the XMLHttpRequest version and it worked too.
var data = null;
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
data = {value: { number: "3" }}; //added
var json = JSON.stringify(data); //added
xhr.open("PUT", 'https://api.trello.com/1/cards/{idCard}/customField/{idCustomField}/item?key={yourkey}&token={yourtoken}');
xhr.setRequestHeader('Content-type','application/json'); //added
xhr.send(json); //modified
The point is that you should 1) set the request Content-type header to application/json and 2) pass the value via JSON object body.
I tried to edit the live example on the documentation but I it was not possible. I hope they will fix it soon.

How do you get field properties

I'm working on a Sencha app and having trouble accessing the fields of a basic model that I've defined. I use Ext.define to define a model and Ext.create to create an instance of it. According to the docs I should be able to access its fields by calling get.(<fieldname>) on the field, but it's not working and it's returning null. Here's the basic code, along with a jsfiddle.
Ext.define('App.model.Patient', {
extend: 'Ext.data.Model',
config: {
fields: ['admissionGuid',
'firstName', 'middleInitial', 'lastName', 'visitType',
{ name: "visitDate", type: 'date'}]
}
});​
var newVisit = Ext.create('App.model.Patient', {
admissionGuid: 1234,
firstName: "FirstName",
middleName: "MiddleName",
lastName: "LastName",
visitType: "Revisit",
visitDate: new Date()
});
alert(newVisit.get('admissionGuid')); // returns null
Your code is correct using Sencha Touch 2. I've tested it, and it works as expected. Fiddle here using ST: http://www.senchafiddle.com/#6Q9ac
ExtJS and Sencha Touch share similar class systems, but they are not identical.
The data that you passed gets stored in the raw parameter so try this
alert(newVisit.raw.admissionGuid);
This should work
just an alternative way,
we can also access the data inside model by:
*instanceOfModel*.data.*fieldName*
so for example with the given code it will be:
newVisit.data.admissionGuid

insert in sencha touch data store

Could someone please explain how the insert works to add a record in a datastore
with tha fields: "title", "info" and "price"?
because i tried some things and none of them work. and the sencha website doesnt make it very clear.
Adding a new item to an existing Store isn't that hard actually.
First of you will need to configure your model and store. In your question you name the fields 'title, 'info' and 'price'.
Model:
Ext.regModel('myModel', {
fields: [
{name: 'id', type: 'int' },
{name: 'title', type: 'string' },
{name: 'info', type: 'string' },
{name: 'price', type: 'int' }
]
});
Next you configure the store that will hold the data, based on the above model. I think that, in your case, it should be a model without any data preloaded via, for example, JSON?
So lets make a localstorage (empty store). The Store consists of the model (myModel), you give it a storeID (so that you can later on reference the store by this ID). The proxy is localstorage and the unique ID of the Store will be the ID field of the Model.
Store:
var myStore = new Ext.data.Store({
model: "myModel",
storeId: "myStoreID",
proxy: {
type: "localstorage",
id: "id"
}
});
Now, suppose you have some kind of Form (in which the user can add input a title, info and price, and you want to add these items to the existing store on submittal.
Within the handler of the submittal button you now have to 'call' the store, and perform the add function on it. Within this add function you will have to define the params (the model params) and the data to insert.
Below I have used a mixture of fixed data and a variable to insert.
myStoreID.add({ title: "Mijn Titel", info: "Informatie, price: prijsvar });
The store will now be filled will now be filled with an extra data-record which you can use. Lets say for example that the store is attached to a dataview, then you can perform:
dataView.update();
The above isn't a full tutorial, but I think this will help you along?
Just an update of the YDL answer.
As per the dataView should be related to the updated store, the last sentence dataView.update() should not be needed, due to the automatic update of the views related to a store when it change.
new Ext.DataView({
store: MyStore,
itemSelector: 'div.thumb',
tpl: thumbTpl
});
later, if I do the following, the new item should be displayed in views (List, DataView, etc.) that have MyStore as store.
MyStore.add(newItem);
HTH.
Milton Rodríguez.
If you are trying to pass in an object that was returned from a getValue() on your form, make sure that you run a
myStore.sync();
after you have called the add() method, or you wont see it in your browsers local store.
It is Very easy try these
// first get those values and store in locally
var A_select1=Ext.getCmp('select1').getValue(); // get value
localStorage.setItem("Adult1_select1",A_select1); // set localStore
var AdultSalutation={
'Adult1_select1':A_select1, // assign the value
};
var AdultSalutationstore = Ext.getStore('Adult_AdultSalutationstore'); // get store
AdultSalutationstore.add(AdultSalutation); // add object
AdultSalutationstore.sync(); // sync
AdultSalutationstore.load(); // load