Getting the greatest value for a field for all records - netsuite

For our Employee records within NetSuite, we have a custom field called "Employee Number" with an ID of custentity1. I've created a workflow that will automatically create a new employee record and populate various fields but the one I'm having difficulty with is the Employee Number field. All I want to do is to grab the largest employee number there is out of all of the Employee records and add one to it for the new employee record.
The Employee Number field is a free-form text field so I know I'll have to use TO_NUMBER, but anytime I try and reference {custentity1} I keep getting an error saying that field is not found.
UPDATE: I've created a new custom field for our employee records called "Employee No." with an ID of custentity_employeenumber. I've also created a javascript file with the following:
function getMaxEmployeeNumber(){
var empNumber = nlobjSearchColumn('custentity_employeenumber', null, 'max');
return empNumber;
}
But how to do I get this to work with my records?

NetSuite does have an auto-numbering mechanism built in to its native functionality that most of our customers use for this exact purpose. Is there a special reason this functionality is not being leveraged? This functionality is accessible at Setup > Company > Auto-generated Numbers.
I do not work much with workflows, so I do not know if this same functionality is possible there, but here is how I would solve this in SuiteScript:
Create User Event script that is executed on Before Submit Create event for Customer records
Create a Customer search that has a Search Column for custentity1 with a summary type of max
new nlobjSearchColumn('custentity1', null, 'max');
Running this search should give you 1 result, which is the maximum customer number. You can then just add 1 to it.
You could create a similar Saved Search in the UI to see what the result set looks like.
This will only really work if the field is a Number, not Text. I would suggest changing the field to an Integer field if you know that it will always be a number. This may clear out existing data, so first you could export all customers and their number to Excel and then do a CSV import after changing the field.

How are you looking for the last employee in a workflow?
I know this can be done in js:
Search employees - returns max 1000
For number of employees give me the custentity1 of the last one - nlapiLookupfield('employee',employees[employees.length],'custentity1')
Add +1 and save on new record

If you use this search column
nlobjSearchColumn('custentity1', null, 'max');
You can also sort it in decreasing value so that the first result is always the max. Something like
nlobjSearchColumn('custentity1', null, 'max').setSort(true);

Related

Nersutie Advanced Saved Search

I'm new to Netsuite. I have a task of creating a saved search to display the three columns from the custom record. First Client, then Superclass and lastly from the superclass,client group I want to display the count of records having status "Wiped or Destroyed". I have grouped the record based on superclass and client successfully. Now I am experiencing problems to display the count of records having status = "Wiped or Destroyed" in the third column. I need someone to tell me how exactly it could be done?
screen-shot of result tab in saved search
You can use a text formula with a case statement to achieve this:
CASE WHEN {status} = 'Wiped or Destroyed' THEN {internalid} END
Set the Field to "Formula (text)" and the Summary Type to "Count".

How to get view data to copy to field in document?

I'm currently tasked to redesign an application form where several fields will need to auto-fill based on the data from a specific field when it is entered.
Since I'm relatively new to LotusNotes, my boss hinted at me to first create a view which displays the fields to auto-fill. Which I did:
| Visitor Name | Company Name | Contact No | Date Entered |
Visitor Name is the field which will determine the data for Company Name and Contact No when it auto-fills in the form. Date Entered will see which data is the most recent and will use that. Also the field must be set as Editable to allow user to change the data if need be.
However, when trying to modify the form, I can't quite get how to link the view together with my desired field in the form.
I tried #DbLookup and created the formula
#If(VisitorName = "";"";VisitorName != ""; #DbLookup("" : "" ; "Local":"D:\LotusNotes Project\HR002a.nsf"; "Visitor View";#text(ContactName);#Text(CompanyName));"")
But it doesn't seem to work when I place it in Default Value or Input Translation. Even changing the filed to Computed doesn't seem to help as well.
What else am I missing in my formula?
You could simplyfiy your formula
#If(VisitorName != ""; #DbLookup("";#dbname;"Visitor View";#text(ContactName);2;[FailSilent]);"")
I am assuming this is a form used in the Notes clieny, not on the web. If this is a web form, you need a different approach.
You could very well use #DBLookup for that task. To improve performance, concatenate all the values into one column, perform the #DbLookup on the form, retrieving the concatenated values, then split them into separate values and populate the different fields.
You could also use Lotusscript. You want to look at the NotesView class and the NotesViewEntry class (assuming you want to build it for performance). Use the ColumnValues property of the NotesViewEntry class to read the columns in the view. Remember that the first column needs to be sorted.
Or your company could hire someone that already know Notes and Domino, and have that done in an hour. That would probably be financially a better choice than you spending hours or days on this fairly simple task. There are many of us here (me included) who could jump in and fix this for your company.

Set field value based on saved search

I want to set total sold quantity in last six months in custom field on item and want to use that for other customization.
I am able to display it on the field using summary search but not able to save it.
The value of a Saved Search custom field is calculated every time the record is displayed and not stored in the database, which is why you can't use it directly in other customizations. A workaround is to have a second field which stores the value, and then you can use a Workflow or script to copy the field value.

SharePoint 2013 Calculated Field not working all the time

I have a form where I need to include a calculated field. I made a very simple test using a calculated field where the formula is "=ID". I just want to confirm that the value I'm getting in the view is the same as the ID of the record in the list.
I press NEW and create a new record. Then when I see the new record in the view, the first column is the ID (let's say 11), then some proper fields form the form and finally the calculated field that instead of showing me the value 11, it shows 0.
Then I follow the following steps:
I go to Settings, List Settings
Click on the calculated field to edit it (only edit it with no modifications) and press on OK (no modifications to the calculated field at all)
Go back to the list of records and now the calculated value shows me the value 11
I google it but no solution.. there is someone say that this issue is from the column ID, it mean 'when you initially save the item is that there is no value for "ID" yet' !
and this isn't my state, the column id is incremented normally when add new item.
Anyone can help me to identify with the calculated field does not shows 11 automatically after the record is saved?
or by follow another solution like using a workflow 2013..
Thanks a lot
You can not use [ID] in a Calculated Column formula.
I won't bother with the long technical explanation...
If it was possible, Microsoft would have added it to the list of Fields you can select when writing a Formula.
Workaround is to make a simple SharePoint Designer Workflow which kicks off on Item creation and saves the ID value to another Column.
You can then use that Column in your Calculated Formulas
If you're doing anything front-end.. jQuery.. CSR/JSlink.. the ID value is available in the attribute id of the Item TableRow (TR) as x,id,y
so you can get the id with
var ID={element}.getAttribute('id')[1]
Update #1 - example code used:
="<a href='/sites/ru1/Lists/ao26c/DispForm.aspx?ID='
target='_blank'><img src= '_layouts/images/blank.gif'
onload= ""var row=this;
while(row.tagName!='TR'){row=row.parentNode};
this.parentNode.href+=row.‌​getAttribute('id').split(',')[1];
"">Открыть</a>"

Updating a table Access and Excel VBA

I have one table called: Transaction. This table has the following fields: (ID,ProductName,Amount,Date) placed in an excel sheet that is connected with MS Access database. ID is the only unique field. Sometimes, my user submits a transaction that has let's say 5 records. Then, they want to modify the submitted data in case if they entered incorrect amount and they want to correct it. I want to write a code in VBA that will do the update. my current query is:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount)
where Date=#date;
This query does not work fine because obviously it replaces all the records data with the data of the last resubmitted record because my condition is weak. My difficulty is that I can't find a good condition in the where clause that will do the update a record by record accordingly.
Please help,
You will need to use the unique id of the record, in your case the ID field to guarantee you are updating the correct record.
Something like the following:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount) where ID = "id of record you want to update"
Enjoy!

Resources