updating a value in security rules, is causing a failed update when there is checking against the resource document on one of the instances - firebase-security

I have the following function that works fine until I try to update the gender or age fields
since there is a check against the src doc that is causing the failure how to go about it in a way that will allow updates to other fileds ?, without erroring out when there is no (count) in the incoming update ?
batch.update(doc(db, 'docPath', { gender: selected.gender });
function dataCheckUpdate(requestData, resourceData) {
return (
// gender
requestData.gender is string &&
// age
requestData.age is number &&
// count
requestData.count is number &&
requestData.count == resourceData.count + 1 &&
// (!('count' in requestData.keys()) || (requestData.count == resourceData.count + 1)) &&
requestData.count <= 2 &&
);
}
// call
dataCheckUpdate(request.resource.data, resource.data)

Related

Convert Salesforce IDs from 15 digit to 18 digit using sql code/function

We are currently pulling in data from SalesForce to SQL Database tables. There are 2 custom fields on different objects that were created for the Lead ID and a look up for which event/task is linked (this can be an account id, contact id, or lead id). Both of these are pulling over the 15 digit ID.
I am trying to find out if there is any SQL code or a SQL function that will allow me to convert that 15 digit to an 18 digit ID.
I need to have that 18 digit ID to join back to the other objects.
We have already tried using the CASESAFEID(Id) function in SalesForce, but with the API that was already set up and the visibility levels our particular ETL is not showing that field. Also, we would need to get a consultant to mess with the look up column.
I would like to take the 15 digit ID and convert it to the 18 digit code. If the SalesforceID is 0035000002tAzbu, how do I get the converted 18 digit value to be 0035000002tAzbuACC. I need to get that last 3 digits using SQL query or SQL function.
you could write a custom function in your sql database.
e.g. in snowflake, you can make a function like this
CREATE OR REPLACE FUNCTION dw.my_schema.f_sfdc_ch15_to_ch18("txt" string)
RETURNS string
LANGUAGE JAVASCRIPT
AS '
if ( txt == undefined || txt == "" || typeof txt == "undefined" || txt == null) {
return ;
} else {
var id15, id18;
if (txt.length == 18) {
return txt;
} else if (txt.length == 15) {
id15 = [txt.trim()];
} else {
return "";
}
for ( var x=0; x < id15.length; x++ ) {
var s = "";
for ( var i=0; i<3; i++) {
var f = 0;
for (var j=0; j<5; j++) {
var c = id15[x].charAt(i*5+j);
if (c>="A" && c<="Z") {
f+=1<<j;
}
}
s += "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345".charAt(f);
}
id18 = id15[x]+s;
}
}
return id18.toString();
';
and use it like this
select dw.my_schema.f_sfdc_ch15_to_ch18(id15) from mytable;
This value can be computed. Check out this flowchart.
Source: https://stackoverflow.com/a/29299786/3135974

GL-Category Sequence in adempiere

I want to make a GL-Category Sequence like document sequence for every cash journal.
I added a field in cash journal window called journal number.
I want to generate a number for every cash journal and increment it by 1?
The document sequence is managed by the PO.java class in ADempiere. To use it, you need to add a column with the column name "DocumentNo" to your table. You will need to add the entry in the Sequence table to keep track of the numbers.
Here is the code from PO.java which is run when the record is first saved.
// Set new DocumentNo
String columnName = "DocumentNo";
int index = p_info.getColumnIndex(columnName);
if (index != -1 && p_info.getColumn(index).ColumnSQL == null)
{
String value = (String)get_Value(index);
if (value != null && value.startsWith("<") && value.endsWith(">"))
value = null;
if (value == null || value.length() == 0)
{
int dt = p_info.getColumnIndex("C_DocTypeTarget_ID");
if (dt == -1)
dt = p_info.getColumnIndex("C_DocType_ID");
if (dt != -1) // get based on Doc Type (might return null)
value = DB.getDocumentNo(get_ValueAsInt(dt), m_trxName, false, this);
if (value == null) // not overwritten by DocType and not manually entered
value = DB.getDocumentNo(getAD_Client_ID(), p_info.getTableName(), m_trxName, this);
set_ValueNoCheck(columnName, value);
}
}

WL JSONStore Sort key <field> is not one of the valid strings

I am having an error when trying to sort doing a findAll:
"Sort key dateis not one of the valid strings."
My options are the following (I tried different formats for desc, everyone was throwing the same 'error'):
var options = {sort: [{"date": "desc"}]};
Everything seems fine, the JSONStore works as expected, sorting the returned data, I just want to be sure that the 'error' is indeed a bug or mistake on the worklight.js part and not that I am doing something wrong.
This is the function that checks for a valid sortObj in worklight.js:
/** Checks if sortObj is a valid sort object for a query
* #private
*/
var __isValidSortObject = function(sortObj, searchFields, additionalSearchFields) {
var propertiesValidated = 0,
sortObjKey, sortStr;
for (sortObjKey in sortObj) {
if (sortObj.hasOwnProperty(sortObjKey)) {
if (propertiesValidated > 0) {
WL.Logger.trace('Sort object ' + JSON.stringify(sortObj) + ' has more than one property. Each object must have only one property.');
return false;
}
//check is sortObjKey is lowerCase
if (_.isUndefined(searchFields[sortObjKey.toLowerCase()]) && _.isUndefined(additionalSearchFields[sortObjKey.toLowerCase()])) {
WL.Logger.trace('Sort key ' + sortObjKey + ' is not part of search fields: ' + JSON.stringify(searchFields) + ' or additional search fields: ' + JSON.stringify(additionalSearchFields));
return false;
}
sortStr = sortObj[sortObjKey];
//Check that the string that specifies sorting order says either "asc" or "desc"
**if (__isString(sortStr) && sortStr.length > 0 && (/^(a|de)sc$/i.test(sortStr))) {
WL.Logger.trace('Sort key ' + sortObjKey + 'is not one of the valid strings.');
propertiesValidated++;
} else {
// Here seems to be the problem, shouldn't the trace be before return false?
return false;
}**
}
}
if (propertiesValidated === 0) {
return false;
}
return true;
};
You can clearly see that they do the WL.Logger.trace when the check is fine and that it should be just before return false.
Does anyone that has used sort on a JSONStore receives this trace as well?.
Platform version: 7.1.0.00.20160129-1923
I contacted IBM support and they indeed confirmed that it is a bug that will be solved in the next build.

AJAX filled pulldown shows 5 identical options when there are 5 different options in database

Scratching head here. I've got a pulldown and if I query it in SQL Server Manager Query Window I get 5 different values (these are sample points for a water system).
However, when the pulldown loads, there are 5 options of the first value. Can someone see something I can't?
I narrowed it down to the code below because I held my cursor over "results" which was the final step in my Controller's code, and it showed 5 items all of the same value:
else if ((sampletype == "P") || (sampletype == "T") || (sampletype == "C") || (sampletype == "A"))
{
var SamplePoints = (from c in _db.tblPWS_WSF_SPID_ISN_Lookup
where c.PWS == id && c.WSFStateCode.Substring(0, 1) == "S"
select c).ToList();
if (SamplePoints.Any())
{
var listItemsBig = SamplePoints.Select(p => new SelectListItem
{
Selected = false,
Text = p.WSFStateCode.ToString() + ":::" + p.SamplePointID.ToString(),
Value = p.WSFStateCode.ToString()
}).ToList();
results = new JsonResult { Data = listItemsBig };
}
}
return results ;
}
I have had a similar problem in nHibernate, it was caused by how I defined my primary keys/foreign keys in the ORM, leading to a bad join and duplicate values.

Creating level codes with action script 2.0

I want to create level codes, like in sea of fire (http://armorgames.com/play/351/sea-of-fire)
I have a text input box with the instance name "code" and a button that has this code:
on (release) {
if (code = 96925) {
gotoAndStop(4);
}
if (code = 34468) {
gotoAndStop(5);
}
if (code = 57575) {
gotoAndStop(6);
}
if (code = 86242) {
gotoAndStop(7);
}
if (code = 99457) {
gotoAndStop(8);
}
if (code = 66988) {
gotoAndStop(10);
}
if (code = !96925 && !34468 && !57575 && !86242 && !99457 && !66988) {
gotoAndStop(3);
}
}
I've tried to use code.text instead of just code, I've also tried quotes around the numbers, also I tried both together but it always sends you to frame 10 even if the code is invalid.
You need to use conditional operator (==), not equality operator (=) in 'if' condition
Also if 'code' is a text field then you need to use code.text
You can put trace to check for the value of code.
I do not understand your last if condition
Instead you can use if - else if - else here.