I added a wizard in action of model 'product.template', I want to get 'active_ids' in wizard, I trying with this code:
class Wizard(models.TransientModel):
_name = "product.wizard"
product_template_ids = fields.Many2many('product.template')
#api.model
def default_get(self, fields):
res = super(Wizard, self).default_get(fields)
res['product_template_ids'] = self.env.context.get('active_ids', False)
return res
But , I got this error : raise exception.with_traceback(None) from new_cause
TypeError: 'int' object is not subscriptable
What's wrong ? Any help please?
Thanks.
Try this:
First check what you are getting with this self.env.context.get('active_ids', False), if it gives id inside list i.e [23] then use many2many filling operation i.e
res['product_template_ids'] = [(6, 0, self.env.context.get('active_ids', False))]
and if it's giving ID i.e 23 then use:
blank_list = []
blank_list.append(self.env.context.get('active_ids', False))
res['product_template_ids'] = [(6, 0, blank_list)]
Related
data = JSON.parse(data);
console.log(data.Jobs[0].Job.Settings.Inputs[0].FileInput)
ftr = data.Jobs
rslt = ftr.filter(function(element){
return element.Job.Settings.Inputs[0].Fileinput == 's3://transvideo-source71e471f1-knewdmajkw29/assets01/Pexels Videos 2219383.mp4';
});
i want to get one array element by fitering the object type data(use JSON.parse(data))
i can't get filtered element and just get below error message
Error [TypeError]: Cannot read property 'Settings' of undefined
how to i can get filtered data by using 'Fileinput'(element.Job.Settings.Inputs[0].Fileinput)
You are filtering data.Jobs, which is an array of Job. But then, you are trying to access element.Job another time. In other words, you are trying to access Job.Job, that's why it's undefined.
const rslt = data.Jobs.filter( Job => Job.Settings.Inputs[0].Fileinput == 's3://...2219383.mp4');
const rslt = data.Jobs.filter( Job => Job.Settings.Inputs[0].Fileinput == 's3://...2219383.mp4');
I am working on a project where I want to check if my variable exists in an object and I want to return the location where it exists.
Here is an example of my object (called data):
[
0: {ArticleNumber: "ART0001", Name: "Ticket1", Branche: "Railway1"}
1: {ArticleNumber: "ART0002", Name: "Ticket2", Branche: "Railway2"}
]
Now I have a variable that is:
var articleNumber = "ART0001"
What I now want to do is to check if my variable articleNumber is in my object and then I want to return the number (in this case 0).
Have tried the following code:
var arrayNumber = Object.values(data)
var number = arrayNumber.indexOf("ART0001")
Unfortunately number now returns a -1. What am I doing wrong?
Try
data.findIndex((ele) => ele.ArticleNumber == "ART0001")
I added a filed company(It's a char field), when creating a payment ,I want to set default value.
When creating new payment, the value wasn't displayed in the form view . But , when printing 'my_company' , I got the correct result.
What's wrong please?
class AccountPayment(models.Model):
_inherit = "account.payment"
#api.model
def get_company(self):
if self.move_type == 'in_invoice':
my_company = self.env.user.company_id.name
self.company = my_company
else:
self.company = ''
company = fields.Char(string='Company ', default=get_company)
Thanks.
You need to return the value.
Here is the correct code
class AccountPayment(models.Model):
_inherit = "account.payment"
def get_company(self):
if self.move_type == 'in_invoice':
my_company = self.env.user.company_id.name
return my_company
else:
return None
company = fields.Char(string='Company Name', default=get_company)
I've created a function with three parameters (the client, the value I'm looking for in a table, the value new value to update), but until know I don't know how to update the cell with the determined value.
So far, I succeeded to look for the value in the table, but I cannot update the final cell with the value in parameter of the function. What is the way to do that?
async function modif(client, id1, id2)
{
const gsapi = google.sheets({version:'v4',auth: client });
for (i = 0; i < 50; i++)
{
const opt1 = {spreadsheetId: 'XXX', range: 'Sheet1!A' + (3+i)};
let data1 = await gsapi.spreadsheets.values.get(opt1);
if (parseInt(id1) === parseInt(data1.data.values))
{
const opt2 = {
spreadsheetId: 'xxx',
range: 'Sheet1!B' + (3+i),
valueInputOption: 'USER_ENTERED',
resource:{values : id2}
};
let res = await gsapi.spreadsheets.values.update(opt2);
console.log("modifications OK");
return;
}
}
}
I am supposed to have an updated cell, however instead I receive an error message saying : Invalid value at 'data.values'. Error is at the line resource:{values : id2}
Does anyone know how to solve this little error (I guess), I spent 2 hours on this error yesterday without being able to solve it :(
Thanks a lot in advance for your help,
I finally found out what was the problem... When I looked at the documentation here : https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values, I discovered the parameter "values" is an array of arrays...
As a result I only had to change my syntax to goes from : resource:{values : id2} to : resource:{values : [[id2]]}
Cheers,
I want to set the value for the multi-select with existing values in that field.
(i.e) If the Filed has the values "A , B" means I wants add the New Value "c" with Existing Values So, Result would be "A,B,C" .
I used "N/Record' Modules SubmitFields API to set the value for the Multi-select Field like this
CODE : SuiteScript 2.0 version :
Initial Code:
var strArrayValue = new Array();
strArrayValue [0] = "A";
strArrayValue [1] = "B";
strArrayValue [2] = "C";
record.submitFields({
type:'purchaseorder',
id:56,
values:{
custbody_multiselectfield: strArrayValue
},
options: {
enableSourcing: false,
ignoreMandatoryFields : true
}
});
It is showing the error like this : "you have entered an Invalid Type Argument :arg 4"
Updated Code :
var strArrayValue = new Array();
strArrayValue [0] = "A";
strArrayValue [1] = "B";
strArrayValue [2] = "C";
var PORec = record.load({ // Loading Purchase Order Recod
type:"purchaseorder",
id:56,
isDynamic: true
)};
PORec.setValue('custbody_multiselectfield',strArrayValue ); // Setting Value (Array List) for Multi-Select Fields
PORec.save(); // Saving Loaded Record
It is also showing the error: " Invalid custbody_multiselectfield'reference key 31567,31568 "
But if I add an Value as an String instead of String Array it is setting only single value (i.e) overriding the previous values.
Ex: Multi-select has only the "C" value instead of "A,B,C" Values.
Can anyone help regarding this question.
According to NetSuite's documentation, you cannot use this api method to edit or submit select fields - only fields that support inline editing (see SuiteAnswer ID:45158). You may have to load the record with record.load(), modify the values and then submit with record.save().
EDIT: In answer to the updated question, the only thing that appears amiss here is that you are trying to set the values by the display value of the field, where setValue() is expecting the Internal ID of the values. You can either change the values you're populating with the relevant internal IDs, or you could change it to use the setText() method instead:
var strArrayValue = new Array();
strArrayValue [0] = "A";
strArrayValue [1] = "B";
strArrayValue [2] = "C";
var PORec = record.load({ // Loading Purchase Order Recod
type:"purchaseorder",
id:56,
isDynamic: true
});
PORec.setText('custbody_multiselectfield',strArrayValue ); // Setting Value (Array List) for Multi-Select Fields
PORec.save(); // Saving Loaded Record
I tested both these approaches and both work for me.
If using a client script setting multiselect values is simple. In my case I was searching for subordinates of an employee. For each result I push the internalid of the subordinate (employee record) to an array. Then on my multiselect field of type 'Employee' I set the values like below:
var subordinates = [];
// do search and push internalids of employees
currentRecord.setValue({
fieldId: 'custrecord_emp_subordinates',
value: subordinates
});
Hopefully this helps someone!
If you are loading the record everytime you want to update the multi-select field value, you can fetch the data in the field and store it in a variable.
var multiSelectData = record.getValue({
fieldId:''
});
The data will be in the form of an array, so you can push your data in the array.
multiSelectData.push(yourData);
Finally, you can submit the this variable and save the record.
record.setValue({
fieldId:'',
value: multiSelectData
});
Note - Please take care of the datatypes. Typecast if required.