I have encoded string data to base64 format and setted the output to custom field which is type is long text. In the user interface of the record I could see whole output of encoded value. But while try to get the output value with using rec.getText({fieldId:'customfieldname'}) somehow it breaks the value and doesn't return whole value. Is there any limit size of custom field value?
UserEvent script to get the custom field value:
function beforeSubmit(scriptContext) {
try {
var invrecord = scriptContext.newRecord;
var encodedata = invrecord.getText({fieldId: 'customfield'});
log.debug({title:'Custom field value',
details: encodedata});
return true;
}
catch (e) {
log.error({
title: e.name,
details: e.message
});
return false;
}}
return {
beforeSubmit: beforeSubmit, };});
To encode field value I have used code below:
function encodeBase64Binary(strdata) {
try{
var base64EncodedString = encode.convert({
string: strdata,
inputEncoding: encode.Encoding.UTF_8,
outputEncoding: encode.Encoding.BASE_64
});
return base64EncodedString;
}
catch (e) {
log.error({
title: e.name,
details: e.message)}
}
The value of the field contains the value you're looking for, however, log.debug truncates the value to 3,999 characters. That's why you're not seeing the complete value.
Related
I have an array that looks something like this
settings: [
{ key: 'maxImageSize', value: '512' },
{ key: 'maxFileSize', value: '2048' },
{ key: 'searchResultsLimit', value: '10' },
]
I would like to validate the value of each key before saving them to a database.
Example: searchResultsLimit should be greater than 1 but never exceed 20.
I am using Objection.js and express-validator.
Thanks.
Here's a function that returns a boolean based on whether the array is valid or invalid.
function myValidate(settings) {
try {
settings.map((setting) => {
if (validator.toInt(setting.value) <= 1 || validator.toInt(setting.value) >= 20) {
console.log(setting.value);
throw new Error("Invalid");
}
});
} catch (e) {
console.log(e.message);
return false;
}
return true;
}
Turns out validator.js does not provide a validator to check if a number is in range. Check https://github.com/validatorjs/validator.js/issues/330 for details.
In case you want to just ignore the items that are invalid, you can use the filter method instead to get the items in the required range.
I am trying to create an API route where I pass the field in a mongodb database from the URL and it seems to be that the field is not processed properly as I get no result even though the db has entries that match the query.
the url has the following format: localhost:5000/api/animal/find/stripes/yes
in a general form: localhost:5000/api/animal/find/<FIELD>/<VALUE>
The value is handled properly but the field not.
My code to execute the query is as follows:
exports.getAttributeController = (req, res) => {
const field = req.params.field;
console.log(field); //DEBUG
const value = req.params.value
console.log(value); //DEBUG
Animal.find({
field: value
}).exec((err, animal) => {
if (err || !animal) {
return res.status(400).json({
error: 'No Animals found'
});
}
res.json(animal);
});
};
If I use console.log, I see that the correct values have been sent from the URL, and if I hardcode the field like this
Animal.find({
'stripes': value
...
I get a result, only when I try to insert the field variable, I get no result. How can I fix this?
Thanks in advance
You want to evaluate the value of field, so instead you want
Animal.find({
[field]: value // note the brackets that mean use the value of `field`
}).exec((err, animal) => {
I have a partner record where I would like to change the form if the category field is set to a certain value. However, I can't use this with certain SuiteScript functions because changing the form wipes out any changes that were made to the record. I'm trying to work around this using an afterSubmit function that will use record.SubmitFields to change the form and then redirect.toRecord to reload the page with the change. However, it's not changing the form value. Is there a way to do this with record.submitFields? Am I doing something incorrectly?
var currentRecord = scriptContext.newRecord;
var category = currentRecord.getValue('category');
if(category == '3'){
try{
record.submitFields({
type: record.Type.PARTNER,
id: currentRecord.id,
values: {
'customform': '105'
}
});
log.debug('success');
} catch (e) {
log.error({title: 'error', details: e});
}
}
redirect.toRecord({
type: 'partner',
id: currentRecord.id,
});
}
Yes you can. Whenever you create a url for a record you can generally add a cf parameter that takes the form id. It's the same vaule you'd use if you were setting the field 'customform'. So just skip the submitFields part and do:
redirect.toRecord({
type: 'partner',
id: currentRecord.id,
parameters:{
cf:105
}
});
You can also set the custom form using the submitFields call but that only works for some types of records.
If you need to do this in the beforeLoad here is a fragment in Typescript. The trick to avoid an infinite loop is to check to see if you already have the correct form:
export function beforeLoad(ctx){
let rec : record.Record = ctx.newRecord;
let user = runtime.getCurrentUser();
if(user.roleCenter =='EMPLOYEE'){
if(rec.getValue({fieldId:'assigned'}) != user.id){
throw new Error('You do not have access to this record');
return;
}
}else{
log.debug({
title:'Access for '+ user.entityid,
details:user.roleCenter
});
}
if(ctx.type == ctx.UserEventType.EDIT){
var approvalForm = runtime.getCurrentScript().getParameter({name:'custscript_kotn_approval_form'});
let rec : record.Record = ctx.newRecord;
if( 3 == rec.getValue({fieldId:'custevent_kotn_approval_status'})){
if(approvalForm != rec.getValue({fieldId:'customform'}) && approvalForm != ctx.request.parameters.cf){
redirect.toRecord({
type: <string>rec.type,
id : ''+rec.id,
isEditMode:true,
parameters :{
cf:approvalForm
}
});
return;
}
}
}
I am trying to pass a value from my database and then assign that value to a variable in my Vue Component. This successfully gets the data from the database however i get error when assigning that value to a variable in the component:
"TypeError: Cannot read property 'data' of undefined"
Vue Component:
import TransactionsService from '#/services/TransactionsService'
export default {
components: {
},
data(){
return {
transactions: null,
product: null,
amount: null
}
},
async mounted() {
try{
this.transactions = (await TransactionsService.index()).data.transactions
for( transaction in transactions){
this.amount = transaction.amount
}
console.log(amount)
this.userId = this.$store.state.user.priviledge
} catch(error){
this.error = error.response.data.message
}
}
}
I want to assign the value at transaction.amount to the variable amount
In that for ... in loop, transaction is the item's array index, not the item itself. Here is a more common loop:
// forEach
transactions.forEach(transaction => {
this.amount = transaction.amount
})
This loop will work but still doesn't make sense because you will only keep setting this.amount to the next transaction amount and overwriting the last one. If you intended to add them up you could use:
this.amount += transaction.amount
(Note: It's a good practice to use any other loop type with arrays because index order isn't guaranteed with for ... in. Alternatives are forEach, for, or for ... of)
I have two arrays
typeArr = [1010111,23342344]
infoArr={'name':'jon,'age':25}
I am expecting following
[{'name:'jone','age':25,'type':1010111,'default':'ok'},{'name:'jone','age':25,'type':23342344,'default':'nok'}]
Code :
updaterecord(infoArr,type)
{
infoArr.type=type;
response = calculate(age);
if(response)
infoArr.default = 'ok';
else
infoArr.default = 'nok';
return infoArr;
}
createRecord(infoArr,typeArr)
{
var data = _.map(typeArr, type => {
return updaterecord(infoArr,type);
});
return (data);
}
var myData = createRecord(infoArr,typeArr);
I am getting
[{'name:'jone,'age':25.'type':23342344,'default':nok},{'name:'jone,'age':25.'type':23342344,'default':nok}]
with some reason the last record updates the previous one. I have tried generating array using index var but not sure what's wrong it keep overriding the previous item.
how can I resolve this
You are passing the entire infoArr array to your updaterecord() function, but updaterecord() looks like it's expecting a single object. As a result it is adding those properties to the array rather than individual members of the array.
It's not really clear what is supposed to happen because typeArr has two elements and infoArr has one. Do you want to add another to infoArr or should infoArr have the same number of elements as typeArr.
Assuming it should have the same number you would need to use the index the _map gives you to send each item from infoArr:
function createRecord(infoArr,typeArr) {
var data = _.map(typeArr, (type, i) => {
// use infoArr[i] to send one element
return updaterecord(infoArr[i],type);
});
return (data);
}
Edit:
I'm not sure how you are calculating default since it's different in your expected output, but based on one number. To get an array of objects based on infoArray you need to copy the object and add the additional properties the you want. Object.assign() is good for this:
let typeArr = [1010111,23342344]
let infoArr={'name':'jon','age':25}
function updaterecord(infoArr,type){
var obj = Object.assign({}, infoArr)
return Object.assign(obj, {
type: type,
default: infoArr.age > 25 ? 'ok' : 'nok' //or however your figuring this out
})
}
function createRecord(infoArr,typeArr) {
return _.map(typeArr, type => updaterecord(infoArr,type));
}
Result:
[ { name: 'jon', age: 25, type: 1010111, default: 'nok' },
{ name: 'jon', age: 25, type: 23342344, default: 'nok' } ]