I´m supporting API where I need to update validation into javascript method:
function AddCategory() {
var category = $("#category");
var subCategory = $("#subcategory");
if (category.val().length > 0 && subCategory.val().length > 0) {
var grid = $("#lstCategory").data("kendoGrid");
var listGrid = $("#lstCategory").data().kendoGrid.dataSource.data();
var dataS = grid.dataSource;
if (!FindObjectInList(listGrid, "idSubcategory", subCategory.val())) {
dataS.add({
idCategory: category.val(),
category: $("option:selected", category).text(),
idSubcategory: subCategory.val(),
subCategory: $("option:selected", subCategory).text()
});
dataS.sync();
}
else {
InfoMessage("Category", "Selected subcategory cannot add again");
}
} else {
WarningMessage("Warning", "Select category and subcategory...");
}
}
I need to remove this validation:
InfoMessage("Category", "Selected subcategory cannot add again");
But I don´t understand how this method works, anyone can explain me it? Regards
How it works:
First, pass listGrid, idSubcategory and the value returned from subCategory.val() into FindObjectInList. If null is returned (the category does not exist) - then add the new category information passed in. Else, if the function returns true (the category already exists) then serve up the notification to the user via the InfoMessage function.
if (!FindObjectInList(listGrid, "idSubcategory", subCategory.val())) {
dataS.add({
idCategory: category.val(),
category: $("option:selected", category).text(),
idSubcategory: subCategory.val(),
subCategory: $("option:selected", subCategory).text()
});
dataS.sync();
}
else {
InfoMessage("Category", "Selected subcategory cannot add again");
Related
I create a function with name and id of m Select :
function loadDataFiltrosTipoFunc(Memory) {
var statusStoreMotivo = new Memory({
data: [
{ name: "Todos", id: 0 },
{ name: "Cobrança", id: 1 },
{ name: "Aniversariantes", id: 2 }
]
});
dijit.byId("pesqFuncMotivo").store = statusStoreMotivo;
dijit.byId("pesqFuncMotivo").set("value", TODOS);
};
When call to create new register, show me the options in the form.
My Problem is when call the "Edit", I have the id save in the registry, but I can not set the value name and show the other options to change in the Edit.
I made this : (There are comments in the code with my question more detail)
function EditarMensagem(itensSelecionados) {
try {
// first i check if any iten is selected (ItensSelecionados)
// If is ckeked and no has value show message ask to select only one
// else, if is selected only one and has value continue
if (!hasValue(itensSelecionados) || itensSelecionados.length == 0)
caixaDialogo(DIALOGO_AVISO, 'Selecione um registro para Editar.', null);
else if (itensSelecionados.length > 1)
caixaDialogo(DIALOGO_ERRO, 'Selecione apenas um registro para Editar.', null);
else {
// Here i Check the value of the select and put the name
// I don´t shure if is the best way
if (itensSelecionados[0].motivo = 0) {
var motivo = "Aniversariantes";
}
if (itensSelecionados[0].motivo = 1) {
var motivo = "Cobrança";
}
// Here in 'tipoSmsCompor' is my Select.
// I try put the var motivo,
// but don´t set the name, and don´t show the other options of the list
// declared in the function loadDataFiltrosTipoFunc(Memory)
// How I can set the current value and name in the select and the other option to the user can change?
dijit.byId( 'tipoSmsCompor' ).attr( 'value', itensSelecionados[0].motivo);
dijit.byId("dc_assunto").set("value", itensSelecionados[0].mensagem);
dijit.byId("cad").show();
IncluirAlterar(0, 'divAlterarMensagem', 'divIncluirMensagem', 'divExcluirMensagem', '', 'divCancelarMensagem', 'divClearMensagem');
}
} catch (e) {
postGerarLog(e);
}
}
How I can set the current value and name in the select and the other options to the user can change?
I want set the return value and show me the other option in the funcion loadDataFiltrosTipoFunc, but with the value returned .
Thanks all.
I am new to suitescript. Openly telling I hardly wrote two scripts by seeing other scripts which are little bit easy.
My question is how can read a data from sublist and call other form.
Here is my requirement.
I want to read the item values data highlighted in yellow color
When I read that particular item in a variable I want to call the assemblyitem form in netsuite and get one value.
//Code
function userEventBeforeLoad(type, form, request)
{
nlapiLogExecution('DEBUG', 'This event is occured while ', type);
if(type == 'create' || type == 'copy' || type == 'edit')
{
var recType = nlapiGetRecordType(); //Gets the RecordType
nlapiLogExecution('DEBUG', 'recType', recType);
//
if(recType == 'itemreceipt')
{
nlapiLogExecution('DEBUG', 'The following form is called ',recType);
//var itemfield = nlapiGetFieldValue('item')
//nlapiLogExecution('DEBUG','This value is = ',itemfield);
var formname = nlapiLoadRecord('itemreceipt',itemfield);
nlapiLogExecution('DEBUG','This value is = ',formname);
}
}
}
How can I proceed further?
I want to read that checkbox field value in the following image when i get the item value from above
I recommend looking at the "Sublist APIs" page in NetSuite's Help; it should describe many of the methods you'll be working with.
In particular you'll want to look at nlobjRecord.getLineItemValue().
Here's a video copmaring how to work with sublists in 1.0 versus 2.0: https://www.youtube.com/watch?v=n05OiKYDxhI
I have tried for my end and got succeed. Here is the answer.
function userEventBeforeLoad(type, form, request){
if(type=='copy'|| type =='edit' || type=='create'){
var recType = nlapiGetRecordType(); //Gets the RecordType
nlapiLogExecution('DEBUG', 'recType', recType);
//
if(recType == 'itemreceipt')
{
nlapiLogExecution('DEBUG', 'The following form is called ',recType);
var itemcount = nlapiGetLineItemCount('item');
nlapiLogExecution('DEBUG','This value is = ',+itemcount);
for(var i=1;i<=itemcount;i++)
{
var itemvalue = nlapiGetLineItemValue('item','itemkey',i);
nlapiLogExecution('DEBUG','LineItemInternalID = ',itemvalue);
var itemrecord = nlapiLoadRecord('assemblyitem', itemvalue);
nlapiLogExecution('DEBUG','BOM= ',itemrecord);
if(itemrecord == null){
var itemrecord = nlapiLoadRecord('inventoryitem', itemvalue);
nlapiLogExecution('DEBUG','BOM= ',itemrecord);
}
var value = itemrecord.getFieldValue('custitem_mf_approved_for_dock_to_stock');
nlapiLogExecution('DEBUG',"Checkboxvalue = ",value);
if(value == 'F'){
nlapiSetLineItemValue('item','location',i,9);
nlapiSetLineItemDisabled ('item','location',false,i );
}
else{
nlapiSetLineItemValue('item','location',i,1);
nlapiSetLineItemDisabled ('item','location',true,i );
}
}
}
}
}
So I have a registration form for archery contests and I want users to select 2 things (their age category and their bow type).
Once those 2 are selected, I want the next field (select) to show up and be populated with information from my mysql database.
This field is a selection of shooting levels, differenciated in classes.
In the database, I have 4 tables.
1 for age category (id, name)
1 for bow type (id, name)
1 for shoot level (id, name)
1 table to link all above (id, ac_id, bt_id, sl_id)
So based on radio 1 being clicked and radio 2 being clicked, I want to fire a query on the link table to only get the shooting levels which belong to the 2 radio values..
Can anyone please help me with this?
Try this:
$('#age').click(function(){
var age = $(this).val();
var bow = $('#bow').val();
function getShootingLevel(age, bow);
});
$('#bow').click(function(){
var age = $('#age').val();
var bow = $(this).val();
function getShootingLevel(age, bow);
});
function getShootingLevel(age, bow)
{
// ajax call
}
P.S. You can also check if radio is selected or not.
I got it :)
$(document).ready(function() {
$('input[type=radio][name=leeftijdscategorie]').change(function() {
if($('input[type=radio][name=leeftijdscategorie]').is(':checked')) {
if($('input[type=radio][name=schiettechniek]').is(':checked')) {
// Do stuff
GetLevels($('input[name=leeftijdscategorie]:checked', '#inschrijfformulier').val(),$('input[name=schiettechniek]:checked', '#inschrijfformulier').val())
}
}
});
$('input[type=radio][name=schiettechniek]').change(function() {
if($('input[type=radio][name=schiettechniek]').is(':checked')) {
if($('input[type=radio][name=leeftijdscategorie]').is(':checked')) {
// Do stuff
GetLevels($('input[name=leeftijdscategorie]:checked', '#inschrijfformulier').val(),$('input[name=schiettechniek]:checked', '#inschrijfformulier').val())
}
}
});
});
function removeOptions(selectbox) {
var i;
for(i = selectbox.options.length - 1 ; i >= 0 ; i--) {
selectbox.remove(i);
}
}
function GetLevels(agetype,bowtype) {
removeOptions(document.getElementById(\"schietklasse\"));
$.ajax({
url: '/info/wscript.php',
data:
{
agetype: agetype,
bowtype: bowtype
},
type: 'post',
dataType: 'json', // returns response data as json//
success: function(output) {
var selectBox = document.getElementById(\"schietklasse\");
var options = output; //JSON.parse(output);
for(var i = 0, l = options.length; i < l; i++){
var option = options[i];
selectBox.options.add( new Option(option.text, option.value, option.selected) );
}
}
});
}
I basically made this radio check seperate (so double) because I want people to be able to change their choice. Now, it fires a POST to a php file which gets the information and returns it as JSON.
I am trying to populate a sublist in a suitelet with data from a custom saved search that I have already created. My problem is that the sublist is only populating data from fields that correspond to the "type" of saved search I am doing. For example, in this instance the saved search is a "transaction" type search. If, for example, I want to reference a customer field withing the saved search, say "Name" and "Billing Address", this data will not populate the sublist in the suitelet. All other fields that are being referenced in the Transaction record itself populate the sublist fine. I was just wondering if anyone has ever run into the same issue, anyways here's the code I'm trying to implement.
var form,
sublist;
//GET
if (request.getMethod() == 'GET')
{
//create form
form = nlapiCreateForm('Test Custom Suitelet Form', false);
//create sublist to show results
sublist = form.addSubList('custpage_sublist_id', 'list', 'Item List');
//form buttons
form.addSubmitButton('Submit');
form.addResetButton('Reset');
// run existing saved search
var searchResults = nlapiSearchRecord('transaction','customsearchID');
var columns = searchResults[0].getAllColumns();
// Add the search column names to the sublist field
for ( var i=0; i< columns.length; i++ )
{
sublist.addField(columns[i].getName() ,'text', columns[i].getLabel() );
nlapiLogExecution('DEBUG', 'Column Label',columns[i].getLabel());
}
//additional sublist fields
sublist.addMarkAllButtons();
sublist.addField('custfield_selected', 'checkbox', 'Selected');
sublist.setLineItemValues(searchResults)
response.writePage(form);
}
If you review the nlobjSublist docs you'll see that sublist.setLineItemValues can also take an array of hashes. What does work is:
function getJoinedName(col) {
var join = col.getJoin();
return join ? col.getName() + '__' + join : col.getName();
}
searchResults[0].getAllColumns().forEach(function(col) {
sublist.addField(getJoinedName(col), 'text', col.getLabel());
nlapiLogExecution('DEBUG', 'Column Label', col.getLabel());
});
var resolvedJoins = searchResults.map(function(sr) {
var ret = {
id: sr.getId()
};
sr.getAllColumns().forEach(function(col) {
ret[getJoinedName(col)] = sr.getText(col) || sr.getValue(col);
});
return ret;
});
sublist.setLineItemValues(resolvedJoins);
I'm trying to figure out the code behind looking at a new Sales Order that has an item called "Repair" and add a second item called "Repair Cost" before User submit. I'm a bit lost and I welcome any help that can be given. I would like this script to be in Javascript and I will attach it to the Sales Order form in Netsuite to run.
Here is one sample solution:
We will still assume that the items internal ids are Repair = 100 and Repair Cost = 200
function recalc(type)
{
if(type == 'item')
{
var itemId = nlapiGetCurrentLineItemValue('item', 'item'); //Get the Item ID
if(itemId == 100) //Repair Cost
{
//Insert item
nlapiSelectNewLineItem('item');
nlapiSetCurrentLineItemValue('item', 'item', 200); //Repair Cost
nlapiSetCurrentLineItemValue('item', 'quantity', 1);
nlapiSetCurrentLineItemValue('item', 'amount', '0.00');
nlapiCommitLineItem('item');
}
}
return true;
}
Deploy this as client-side code and make sure that the function is Recalc.
To learn more about client side script: https://system.na1.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteFlex/SuiteScript/SSScriptTypes_ClientScripts.html#1016773
First thing you need to do is to get the internal id of the item "Repair" and "Repair Cost".
In this example, let's assumed that the internal id of Repair = 100 and Repair Cost = 200
Here is th code:
function afterSubmit(type)
{
if(type == 'create' || type == 'edit')
{
var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId()); //Load the record
//Loop to all sublist item
var count = record.getLineItemCount('item');
for(var i = 1; i <= count; i++)
{
var item = record.getLineItemValue('item', 'item', i); //This will return the internal id of the item
if(item == 100) //Item is equal to 100; insert one item
{
record.insertLineItem('item', i);
record.setLineItemValue('item', 'item', i, 200); //Repair Cost internal id
record.setLineItemValue('item', 'quantity', i, 1); //You should put some quantity; depending on your account setup all required fields should be set here.
}
}
//Submit the changes
nlapiSubmitRecord(record, true);
}
}
To understand the suitescript API and the fields exposed to sales order check on this Netsuite helpguide:
https://system.netsuite.com/help/helpcenter/en_US/RecordsBrowser/2012_2/Records/salesorder.html