If I needed to run a server code twice for it to action correctly, am I able to store any variables from the first pass, to use in the second pass ?
Like localStorage, has server code this functionality ?
If I needed to run a server code twice for it to action correctly, am I able to store any variables from the first pass, to use in the second pass ?
Like localStorage, has server code this functionality ?
Hello Addy,
Server code doesn't have localStorage variables. You can store it in database (http://devcenter.appery.io/documentat...)
Good idea, I did not think of that. Thank you
Although that is a good idea, I still need to store the _id somewhere, otherwise how will it know what object to pull ?
If it is just one _id, you can write it in server code directly. E.g. Write all information you need in one DB item and read it by its id.
I cannot do that, the information comes from two locations. Hence why I said I need to run the same script twice. Both parts are needed to action the script to the fullest. I have managed to work a way round it though.
Hi Addy.
1 You need to create "scriptsData"("parameterName"(string), "parameterValue"(string)) collection in your DB.
2 Add row to this collection with name "firstScriptItemId" and empty value. http://prntscr.com/3yimzz/direct
3 Add this JS code to your script:
pre
//Set this variables with your values.
var dbID = "52fd3d06e4b0a25c11c89917";
var collectionName = "scriptsData";
var DBLSV = {
getItemId: function(itemName){
Code: Select all
var params = {};
params.criteria = {
"parameterName": itemName
};
var result = Collection.query(dbID, collectionName, params);
Code: Select all
if(result[0])
return result[0]._id;
return 0;
},
getItem: function(itemName){
Code: Select all
var params = {};
params.criteria = {
"parameterName": itemName
};
var result = Collection.query(dbID, collectionName, params);
Code: Select all
if(result[0])
return result[0].parameterValue;
return "";
},
setItem: function(itemName, itemValue){
var itemId = this.getItemId(itemName);
Code: Select all
var result = Collection.updateObject(dbID, collectionName, itemId, {"parameterValue": itemValue});
}
}
/pre
4 Now you can use the following code to get and set "firstScriptItemId" like LSV.
pre
//Set item.
DBLSV.setItem("firstScriptItemId", "helloWorld");
//Get item.
var item = DBLSV.getItem("firstScriptItemId");
/pre
Regards.
FYI - it's great that this was here - I was able to quickly adapt the "Collection.updateObject" code - and put it into a process I just wrote...
Thanks Yurii....
Yurii , Thumps UP, I find allmost any problem I face using your answers.