I am using a MultiInput control to which I am adding Tokens based on input from the user. For this I have used addValidator function to add Token with 'key' and 'text'.
I am looking to add operator (like 'EQ') along with this data to the Token. I found customData aggregation for sap.m.Token control. Can this be used to add operations to the Token along with the key and text fields?
Below code does not work:
return new Token({
customData: [{
key: "range",
value: {
exclude: false,
keyField: "LabelKey",
operation: "EQ",
value1: "sometext",
value2: null
}
}]
});
I was able to add a Token with 'EQ' operation in the following manner.
('text' is the value entered by user in the MultiInput control retrieved using the parameters of addValidator function to the MultiInput control)
return new Token({
key: "range_0",
text: "=" + text
}).data("range", {
"exclude": false,
"operation": ValueHelpRangeOperation.EQ,
"keyField": "ProductId",
"value1": text,
"value2": ""
});
before which I had to define:
var ValueHelpRangeOperation = compLibrary.valuehelpdialog.ValueHelpRangeOperation;
where compLibrary is 'sap/ui/comp/library'
Related
slider_value: {
type: Number,
required: false,
},
This is the Mongoose schema for one of the fields in my MongoDB model.
It may only accept the integer values of 1, 4, and 10.
How can this validator be specified in the schema?
If you only need to store either one of these three values, storing them as a string, and validating using the enum key would be reasonable. For example that could look like this:
{
slider_value: {
type: String,
enum: ["1", "4", "10"],
},
}
Alternatively, if it is a requirement to store them in form of an int, you could use a custom validator to check a value before it's saved. That would look like this:
{
slider_value: {
type: Number,
validate: {
validator: value => value === 1 || value === 4 || value === 10,
message: props => `${props.value} is invalid for slider_value`,
},
},
}
For more details on custom validators and validation in mongoose in generell, here are the mongoose validation docs.
Is there a way to get the default bookmarks with capability APIs?
I tried app.getList('BookmarkList') method, but it doesn't return any parameter identifying that it's a default bookmark.
In order to get the default bookmarks you'll have to create generic object with the following definition:
app.createGenericObject({
qInfo: {
qType: 'sheets'
},
qAppObjectListDef: {
qType: 'sheet',
qData: {
title: '/qMetaDef/title',
labelExpression: '/labelExpression',
description: '/qMetaDef/description',
descriptionExpression: '/descriptionExpression',
thumbnail: '/thumbnail',
cells: '/cells',
actions: '/actions',
rank: '/rank',
columns: '/columns',
rows: '/rows'
}
}
}, sheets => {
console.log(sheets)
})
The key here is the /actions part of the definition which ensures that the actions metadata is received
The resulting layout should include any defined actions, which, for bookmarks will look like this:
{
actionLabel: "A",
actionType: "applyBookmark",
bookmark: "db014c67-ff43-4111-88ff-836b457928e5",
cId: "KzmaWSa",
field: "",
showSystemVariables: false,
softLock: false,
value: "",
variable: ""
}
In the following is the section of code :
Profile is a mongoose shcema object and contains multiple key-value pairs and the function of the code is to update Profile using findOneAndUpdate method passing in profileFields to $set which contains the new key-value pairs.
let profile = await Profile.findOne({ user: req.user.id });
if (profile) {
profile = await Profile.findOneAndUpdate(
{ user: req.user.id },
{ $set: profileFields },
{ new: true }
);
console.log(profile);
return res.json(profile);
}
This code works fine when a value for a key is changed.
eg. Profile.githubusername was abcd and is changed by passing profileFields(in which githubusername is xyz) to $set in the findOneAndUpdate method.
But the code fails when a key-value pair is completely removed.
eg. profileFields object does not contain githubusername key.
In such case the earlier previously stored value of Profile.githubusername persists.
But I need all existing information for profile to be replaced by profileFields such that if a key-value pair is missing from profileFields it is also removed from profile.
Is there a way to achieve this?
TIA
Edit :
I added the following before making the call to findOneAndUpdate(). But this still doesn't work.
let profile = await Profile.findOne({ user: req.user.id });
// for (key in profile)
// console.log(key);
for (key in profile) {
if (Object.keys(profileFields).indexOf(key) === -1) {
console.log('missing key: 'key);
profileFields[key] = '';
}
}
When I console.log(profile) I get:
{
skills: [ 'HTML' ],
_id: 60142f8f9a5bff1f08653478,
user: 60142dc89a5bff1f08653477,
company: 'Self Employed',
bio: 'Useless international',
status: 'Student or Learning',
experience: [],
education: [],
date: 2021-01-29T15:53:51.693Z,
__v: 10,
location: 'Ahemdabad, Gujrat, India',
githubusername: 'k'
}
From what I understand skills, _id, user, company, bio ... githubusername are the only keys in this object.
But on running a for (key in profile) loop I get a lot a other keys as well ,some are :
$__
isNew
errors
$locals
$op
_doc
$init
db
discriminators
schema
collection
$__originalValidate
$__save
$__validate
$__remove
$__deleteOne
$__init
$isMongooseModelPrototype
$__handleSave
save
$__delta
$__version
increment
$__where
remove
delete
How can I loop through only the user defined keys?
You can try:
delete mongooseObject["$init"]
it will delete your key and then u can manipulate other keys
I am using a ValueHelpDialog with range support. So these tokens are generated based upon selection and values entered. e.g. For 'contains' a Token like *abc* is generated and for 'equal to', =abc is generated. These tokens can be fetched on clicking OK on the ValueHelpDialog as seen below.
I need to create a sap.ui.model.Filter for these selections. How can I evaluate the Tokens to retrieve FilterOperator and the value to be filtered?
Kindly assist, Thanks!
You can retrieve the filter data from the token with the data function.
const oProperties = oToken.data("range");
/*
{
exclude: false,
operation: "Contains",
keyField: "PROPERTY_PATH",
value1: "abc",
value2: null
}
*/
const oFilter = new Filter({
path: oProperties.keyField,
operator: FilterOperator[oProperties.operation],
value1: oProperties.value1
});
We can directly get the operator. Follow below steps to get it onclick of ok button on valuehelp dialog.
oEvent.getParameters().tokens
expand the result of above step and go to maggregations->customdata
I am trying to use rest to create fields and picklists, on the web site I created a field as type picklist String and added some items to the list:
Rest url for field:
https://dev.azure.com/{org}/_apis/work/processes/{processId}/workitemtypes/CMMI2.Bug/fields/Custom.AppType?api-version=5.0-preview.2
it is returning this:
{
referenceName: "Custom.AppType",
name: "AppType",
type: "string",
description: "",
url: "https://dev.azure.com/{org}/_apis/work/processes/bd96307e-3d16-44ac-b498-be1a8daff2d5/behaviors",
customization: "custom"
}
Rest URL for picklist:
https://dev.azure.com/{org}/_apis/work/processes/lists/{picklistId}?api-version=5.0-preview.1
this returns:
{
items: [
"All",
"Item2",
"Item3"
],
id: "{picklistId}",
name: "picklist_{diffGuidFromPickListId}",
type: "String",
isSuggested: false,
url: "https://dev.azure.com/{org}/_apis/work/processes/lists/{picklistId}"
}
Here is documentation for this:
https://learn.microsoft.com/zh-cn/rest/api/azure/devops/processes/fields/get?view=azure-devops-rest-5.0#processworkitemtypefield
Firstly - why is type of field string when it should be picklistString (as per documentation link)?
Secondly - how is the picklist linked to the field?
thanks
The picklistString refers to the name of the type, its actual property is string, so the field type it displays in type is string.
Secondly - how is the picklist linked to the field?
(1) To achieve this, you can use this API:
POST https://dev.azure.com/{organizationName}/{projectName}/_apis/wit/fields?api-version=5.1-preview.2
Here is my request body for you reference:
{
"name": "{FieldName}",
"referenceName": "{the reference name of WIT},
"type": "string",
"usage": "workItem",
"readOnly": false,
"canSortBy": true,
"isQueryable": true,
"supportedOperations": [
{
"referenceName": "{the reference name of WIT}"
"name": "="
}
],
"isIdentity": true,
"isPicklist": true,
"isPicklistSuggested": false,
"url": null
}
Note: Set isPicklist as true, and you can link picklist to this new field.
(2) For UI operation, just add new field, open the drop-down list of type and select picklist(string)/picklist(Integer) as what you need.
The difference between picklist(string) and picklist(Integer) is that picklist(string) allow a pick list of short text string (255 characters or less) values, and picklist(Integer) contains a pick list of Integer values.
It would appear that this is all moot, since the picklistId property cannot be changed once it has been set (i.e. at field creation).
In this reference material, picklistId has "No" as its value for the "Can change?" column: https://learn.microsoft.com/en-us/azure/devops/boards/work-items/work-item-fields?view=azure-devops