I have a parameter Type which is coming as Integer. If Type is 0 we show "Protect" otherwise Unprotect
My Controller is something like this
new Column({
label: new Label({text: "Type"}),
template: new Label({text:
{
path: "ruleType",
formatter: function (value) {
if(parseInt(value) === 0)
return "Protect";
else
return "Unprotect";
}
}}),
filterProperty: "ruleType"
})
My View is something like this
var vQuery = oEvent.getParameter("searchparam");
new Filter({
path: 'ruleType',
operator: FilterOperator.Contains,
value1: vQuery
}),
I have 2 issues
Uncaught Error: Only "String" values are supported for the FilterOperator: "Contains".
When I search with search value : "Protect" filter is not working.
I tried changing FilterOperator.Contains to FilterOperator.EQ string error is gone but search with "Protect" is not working. Can someone help
You can write a custom test function (I always convert the string and search query to lower case).
var vQuery = oEvent.getParameter("searchparam").toLowerCase();
new Filter({
path: 'ruleType',
test: function(value){
return value.toLowerCase().indexOf(vQuery) > -1 //returns true/false
}
});
Related
I have the following schema:
const mySchema = new mongoose.Schema({
x: String,
y: String
})
when a user from the front-end requests in his body:
req.body = {
'x' : '',
'y': ''
}
this results in creating a field in MongoDB, but with an empty string.
I need a way to prevent this behavior by setting the empty strings to be undefined somehow.
Is there such an option in Mongoose? or do I have to predict my own middlewares for that?
You could use the set method for Mongoose Schemas:
const mySchema = new mongoose.Schema(
{
myAttribute: {
type: String,
set: (attribute: string) => attribute === '' ? undefined : attribute,
},
},
{ strict: 'throw' },
);
This will unset the field if the string equals ''.
Use this to trim the strings:
set: (a: string) => a?.trim() === '' ? undefined : a
You don't need mongoose, or a middleware to handle this. You can just write a quick few lines to check for empty values and exclude them from the MongoDB write operation.
Ex:
const newEntry = Object.entries(req.body).reduce((obj, [key, value]) => {
if (value) obj[key] = value
return obj
}, {})
In this example, I convert the req.body into an array using Object.entries and iterate over it with the Array.reduce method, wherein I add key:value pairs to a new object if there is a value to add. Since an empty string value is falsey I can do a simple if check on the value. I then assign the return of the reduce method to the variable newEntry. Then I would then take the new entry and create the MongoDB document with it.
This could be extracted into a helper method and reused in any of your routes that need to check remove empty values from an object.
Docs on Array.reduce
Docs on Object.entries
I have a CDK project and I need to have input parameters and some of them have to be optional.
In my code I need to have a value in any case, so I'm looking a way to set a value if the user left the field empty.
I found some things with Fn.conditionIf and CfnCondition but I don't understand how to use them to achieve what I want.
Here is what I have:
const param1 = new CfnParameter(this, "Param1", {
type: "String",
description: "Myparam",
});
Later on my code I'm getting the value and here I need to set something if is empty:
var myObj = {
myParamFromUser: param1.valueAsString,
};
If I use default value field, that value is displayed on the Console and the field has already the value. I want to have the field empty on the Console.
How to set a value if param1 is empty?
I made it work:
const myCfnParam = new CfnParameter(this, "Param", {
type: "String",
description:
"Input param",
});
const myCondition = new CfnCondition(this, 'Condition', { expression: Fn.conditionEquals(myCfnParam, '') });
const myValue= Fn.conditionIf(myCondition.logicalId, 'MY_STRING', myCfnParam.valueAsString).toString();
I have the following code which returns the internal ID of a sales order by looking it up from a support case record.
So the order of events is:
A support case is received via email
The free text message body field contains a reference to a sales order transaction number. This is identified by the use of the number convention of 'SO1547878'
A workflow is triggered on case creation from the email case creation feature. The sales order number is extracted and stored in a custom field.
The internal ID of the record is looked up and written to the console (log debug) using the workflow action script below:
*#NApiVersion 2.x
*#NScriptType WorkflowActionScript
* #param {Object} context
define(["N/search", "N/record"], function (search, record) {
function onAction(context) {
var recordObj = context.newRecord;
var oc_number = recordObj.getValue({ fieldId: "custevent_case_creation" });
var s = search
.create({
type: "salesorder",
filters: [
search.createFilter({
name: "tranid",
operator: search.Operator.IS,
values: [oc_number],
}),
],
columns: ["internalid"],
})
.run()
.getRange({
start: 0,
end: 1,
});
log.debug("result set", s);
return s[0];
}
return {
onAction: onAction,
};
});
I am trying to return the resulting internal ID as a parameter so I can create a link to the record on the case record.
I'm getting stuck trying to work out how I would do this?
Is there a way to store the value on the case record, of the internal ID, that is looked up? (i.e.the one currently on the debug logs)?
I am very new to JS and Suitescript so am not sure at what point in this process, this value would need to be stored in the support case record.
At the moment. the workflow action script (which is the part of the workflow the above script relates to) is set to trigger after submit
Thanks
Edit: Thanks to Bknights, I have a solution that works.
The workflow:
The new revised script is as follows:
*#NApiVersion 2.x
*#NScriptType WorkflowActionScript
* #param {Object} context
*/
define(["N/search", "N/record"], function (search, record) {
function onAction(context) {
var recordObj = context.newRecord;
var oc_number = recordObj.getValue({ fieldId: "custevent_case_creation" });
var s = search
.create({
type: "salesorder",
filters: [
search.createFilter({
name: "tranid",
operator: search.Operator.IS,
values: [oc_number],
}),
],
columns: ["internalid"],
})
.run()
.getRange({
start: 0,
end: 1,
});
log.debug("result set", s[0].id);
return s[0].id;
}
return {
onAction: onAction,
};
});
On the script record for the workflow action script, set the type of return you expect. In this case, it would be a sales order record:
This would allow you to use a list/record field to store the value from the 'search message' workflow action created by the script
the result
Edit 2: A variation of this
/**
*#NApiVersion 2.x
*#NScriptType WorkflowActionScript
* #param {Object} context
*/
define(["N/search", "N/record"], function (search, record) {
function onAction(context) {
try {
var recordObj = context.newRecord;
var oc_number = recordObj.getValue({
fieldId: "custevent_case_creation",
});
var s = search
.create({
type: "salesorder",
filters: [
search.createFilter({
name: "tranid",
operator: search.Operator.IS,
values: [oc_number],
}),
],
columns: ["internalid","department"],
})
.run()
.getRange({
start: 0,
end: 1,
});
log.debug("result set", s[0]);
recordObj.setValue({fieldId:'custevent_case_sales_order', value:s[0].id});
// return s[0]
} catch (error) {
log.debug(
error.name,
"recordObjId: " +
recordObj.id +
", oc_number:" +
oc_number +
", message: " +
error.message
);
}
}
return {
onAction: onAction,
};
});
Depending on what you want to do with the order link you can do a couple of things.
If you want to reference the Sales Order record from the Support Case record you'd want to add a custom List/Record field to support cases that references transactions. (ex custevent_case_order)
Then move this script to a beforeSubmit UserEvent script and instead of returning extend it like:
recordObj.setValue({fieldId:'custevent_case_order', value:s[0].id});
For performance you'll probably want to test whether you are in a create/update event and that the custom order field is not yet filled in.
If this is part of a larger workflow you may still want to look up the Sales Order in the user event script and then start you workflow when that field has been populated.
If you want to keep the workflow intact your current code could return s[0].id to a workflow or workflow action custom field and then apply it to the case with a Set Field Value action.
I need help with the following code. The uncommented code works fine, but I need to get the commented code to work. See //value: releaseStartDateISO in my code below. Specifically, filter-2 doesn't work. I want to display defects that are active (ie, filter 1- not closed) or defects with a Closed Date greater than Release Start Date (filter 2). This will give me all active defects plus any that were closed during the current sprint. I tried converting Release Start Date to ISO, but this doesn't work. It seems like rally is not recognizing ReleaseStartDate and I don't know why. Note: This is the code from rally git. I added the "or filter" https://github.com/RallyApps/app-catalog/tree/master/src/apps/defectsummarymatrix
Thanks for your help!
_showComponentIfNeeded: function(component) {
if (component && component.isHidden()) {
component.show();
}
},
_initializeAllDefectStore: function(release) {
//var releaseStartDate = release.get('ReleaseStartDate');
//var releaseStartDateISO = Rally.util.DateTime.toIsoString(releaseStartDate,true);
var filter = Ext.create('Rally.data.QueryFilter', {
property: 'State',
operator: '!=',
value: 'Closed'
});
filter = filter.or({
property: 'ClosedDate',
operator: '>',
//value: releaseStartDateISO
value: '2014-09-10'
});
filter.toString();
if (this.releaseFilter && this.defectModel) {
this.allDefectStore = Ext.create('Rally.data.wsapi.Store', {
model: this.defectModel,
fetch: ['State','Priority'],
autoLoad: true,
limit: Infinity,
context: this.getContext().getDataContext(),
filters : [this.releaseFilter,filter],
listeners: {
load: this._onAllDefectStoreLoaded,
scope: this
}
});
}
},
_onAllDefectStoreLoaded: function(store, records, successful, eOpts) {
this._initializeMatrixTable();
this._populateMatrixTable(records);
this._createPriorityRecords(records);
this._updateMatrixGrid();
this.setLoading(false);
},
What is the value of release.get('ReleaseStartDate')? Is it possible the release record you have does not have that field populated?
I've been trying to retrieve a date value and an integer value from the database, using the following code:
var l_alsChampsMois, l_stoDonneesMois;
try {
l_alsChampsMois = [
{name: "date_mois", type: "date", dateFormat: "Y-m-d"},
{name: "indice", type: "integer"}
];
l_stoDonneesMois = new Ext.data.JsonStore({
fields: l_alsChampsMois,
autoLoad: false,
proxy: {
type: "ajax",
url: "/commun/req_sql/req_ind_per_mois.php",
reader: {
type: "json",
root: "rows"
},
// some configs to use jsFiddle echo service (you will remove them)
actionMethods: {
read: "POST"
},
extraParams: {
key:"test"
}
},
listeners: {
load: function(objStore, alsLignes, blnOk, objOptions) {
window.alert("Mois fin : " + objStore.getAt(0).get("date_mois"));
}
}
});
l_stoDonneesMois.load({params: {
p_idsoc: l_strIdSociete,
p_mois: l_datDebut.getMonth() + 1,
// getMonth renvoie 0 pour janvier, etc.
p_annee: l_datDebut.getFullYear(),
p_debut: 1,
p_etape: 1
}
});
with l_strIdSociete and l_datDebut being variables previously assigned and /commun/req_sql/req_ind_per_mois.php the PHP page that retrieves the data and converts it to JSON.
It seems to work fine (indeed, Firebug tells me the load does retrieve a data structure with "date_mois" and "indice" containing the values I expect them to), only the window.alert returns undefined. If I replace "date_mois" with "indice", it returns the expected value for "indice".
I've tried to use objStore.getAt(0).getData()["date_mois"], to no avail.
My only clue about this is that "date_mois" in the data structure shown by Firebug is an Object, but even so it shouldn't be undefined, now should it? I looked up http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Field-cfg-type that wasn't exactly forthcoming with straight answers.
So what did I do wrong there?
If you need current time you can use php time function(note: it returns seconds, JS uses milliseconds), in another case you need to convert by mktime function.