What does your context object look like?
# suitescript
b
What does your context object look like?
m
Copy code
{
  "id": "193724",
  "recordtype": "customer",
  "sublists": {
    "recmachcustrecord121": {
      "currentline": {
        "custrecord120": "4",
        "custrecord122": "abc1 address1",
        "custrecord123": "1",
        "id": "10736",
        "owner": "183791"
      }
    }
  }
}
unction put(context) { doValidation([context.recordtype, context.id], ['recordtype', 'id'], 'PUT'); var rec = record.load({ type: context.recordtype, id: context.id }); for (var fldName in context) if (context.hasOwnProperty(fldName)) if (fldName !== 'recordtype' && fldName !== 'id') rec.setValue(fldName, context[fldName]); var result= rec.save(); return String(result);
It always return 200. I am able to update company name and other similar fields. But when trying to add a service then it does not and still returns 200
b
there are problems with the code and how you are using it with NetSuite's api
m
can you advice whats the issue?
it is setting property
b
the way your code is structured, it is doing
Copy code
rec.setValue("sublists", {
  recmachcustrecord121: {
    currentline: {
      custrecord120: "4",
      custrecord122: "abc1 address1",
      custrecord123: "1",
      id: "10736",
      owner: "183791"
    }
  }
});
its trying to set the sublist field to whatever your object
there is no field named sublist, so nothing will happen
m
ohk
b
you need to change the way your code processes the sublist key, and you need to use NetSuite's sublist apis to do so
m
I used GET and tried to set the input json according to the GET result.
but can you advice how can I use Netsuite's sublist apis to do this?
you can start there for learning about sublists
its in suitescript 1, but the concepts are the same
the code will be different
pay extra attention to the
Working with Sublist Line Items
section and its subsections
m
how will I come to know type of sublist like
var record = nlapiCreateRecord('vendorbill');
instead of vendorbill
and fieldvalues
b
do you need to know the difference between a record and a field?
m
no that I know
m
I need to know how I will cometo know about which type of record need to input
b
the area in section 3 is a sublist
usually the name of the sublist is the same as the child subtab its in
m
I did not get you
b
in this case its item pricing
b
no
its the What is a Sublist page
m
yes I saw that
is this the function you are refering? function beforeLoadSublist(type, form)
b
no
im trying to describe what a sublist is
how to find its id
and then how to find the fieldIds of the sublist
m
ah. But I did not get id and fieldname
I got the field nmes
but not the sublist id
b
the area enclosed by the 3rd highlited area is the item pricing sublist
the name usually matches the name of the subtab
the id usually is the name without spaces
m
I understand the sublist, but trying to understand its name that will be used to add record
b
so for the sublist named item pricing, its id is itempricing
you can usually confirm it in the record browser
m
let me share screen shot and ask
b
there is a section with all the sublist names and ids
m
message has been deleted
here I want to add a cloudconnectcircuit service
that is even one more level in sublist
b
I personally would recommend you learn how the native sublists work before jumping to a child record sublist
m
yes I understand as my sublist name is "Services" so it will be the id
but here CloudConnectCircuits is child of sublist
b
Services is the parent subtab
m
means services is the sublist?
b
services is not a sublist. services is a subtab
m
sorry I mean "CloudConnect Circuits " is sublist?
b
CloudConnect Circuits is the name of the child subtab. It is also the name of the sublist since NetSuite usually names the child subtab after the name of the sublist
m
and how to check the datatype of fields?
b
m
yes
I analysis that thing. there are 3 mandatory fields
address is free-form text
custrecord123 is list/record
status is also list/record
also I found its for all this
how to add type as it is List/record
?
b
there are 2 general ways to set select fields for a sublist
you can use Record.setSublistValue (https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=section_4273166777.html) with the internal id of the select option as the value
or you can use Record.setSublistText (https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=section_4273167591.html) with the name of the select option as the text
if you are using dynamic mode, you use Record.setCurrentSublistValue or Record.setCurrentSublistText instead
m
how to add type as it is List/record
b
type is not a parameter for setSublistValue or setSublistText
m
I understand but where I can check its values and its types
b
go the the custom field on the custom record type page
the source should be set on the List/Record Field
from there, its a guessing game on finding the matching custom record, custom list, or native record
m
are you saying customiztion->record types?
b
that will be the list of custom records in your account
find your custom record (I think its named CloudConnect Circuit)
click it to go to its custom record type page
on that page should be the list of fields
click the field you want additional information on
m
you mean customization->record types and then find CloudConnect Circuits?
I found CloudConnect Circuits in customization -> record types
b
good
m
clicked on it
I am able to see ids for all records. but as I said for type if it is list/record
then how can I check the list items and type of list item to insert new item
b
there should be a sublist column that says List/Record
that shows the source list for the field
m
its says Circuit Statuses under List/Record
b
thats either a custom record or a custom list
look for a matching record or list in your custom record types or custom lists
m
yes I found
should my code be like objRecord.setSublistText({ custrecord122: 'My demo address for update', custrecord123: 2, custrecord120: 3 });
as I want to input only mandatory fields
b
my advice is to start using Record.setSublistText
m
ok I am bit confused with it. It you can help me to finalize the code.
b
the options object as has 4 parameters
m
CloudConnect Circuits - customrecord333
address - custrecord122
type - custrecord123
status - custrecord120
b
the 4 parameters are sublistId, fieldId, line, and value
m
address is free-form text type is List (with string values and internal ID) status is List (with string values and internal ID)
this is what we need to do
b
you could start with the address field
you will be using Record.setSublistValue to set the value of the field
m
ok
b
4 parameters in the options of Record.setSublistValue
first is sublistId
do you have the internal id of the sublist
m
yes customrecord333 is id for CloudConnect Circuits
b
unlikely, that is a custom record type internal id
m
internal id is 333
how to check line?
should I count the occurance number ?
m
this is pragmatically return of line number, but we need directly
will it be same if I count from top to bottom?
b
not sure what you are trying to say
m
In Custom Record Type I navigate to sublist and see all the fields there.
I hope I just need t start counting from top with 1 and thay is line?
b
i still think you are missing how sublists work
the line represents the 0 index based row number
m
for list, should I send internal id or values?
b
not sure what you are trying to say here
m
for List/record there are two things. One the string values and other internalids
b
you use the internal id with setSublistValue or you use the string value (name) with setSublistText
the preferred method is internal id with setSublistValue since its more precise
m
I have three mandatory fields so pls verify if below seems fine Record.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord122', line: 7, value: 'address add for demo' }) Record.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord123', line: 9, value: 3 }) Record.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord120', line: 5, value: 2 })
b
unlikely this is what you want
line represents the tow number in the sublist
m
tow-row?
b
*row number
m
yes I cross verify the line number by counting from 0
I am using below method for inset/POST function post(context) { doValidation([context.recordtype], ['recordtype'], 'POST'); var rec = record.create({ type: context.recordtype }); for (var fldName in context) if (context.hasOwnProperty(fldName)) if (fldName !== 'recordtype') rec.setValue(fldName, context[fldName]); var recordId = rec.save(); return String(recordId); }
and I want to add this sublist at the time of creation then will it be like below after I called var recordId = rec.save(); rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord122', line: 7, value: 'address add for demo' }) rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord123', line: 9, value: 3 }) rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord120', line: 5, value: 2 })
or I should first load the record by id then need to perform?
b
message has been deleted
the line does not refer to the row of the field sublist on the custom record type
it refers to which row you want to modify on the record you are modifying (in this case Client)
I still say you should start on any of the standard sublists instead of a custom one
m
to retreive line numbe ryou provide me the programmatic way, for which I need to run script, is there any direct way to check line?
b
when you use setSublistValue, you choose which line you want to modify
if you are modifying an existing line, you choose the line you want to modify
if you are adding a new line, you choose a line one bigger than the existing count
for example, if there are 4 existing lines, you would use getLineCount to discover that there are 4 lines
and then choose line 4 as the line to modify (remember line is 0 index based)
m
that's confusing for me. I am just trying to add a new record with 3 fields. Is there any direct way to find line number?
I am just trying to insert red marked mandatory fields for sublist
message has been deleted
b
im not sure there is anything more direct than using getLineCount to add a new line to a sublist
you can use dynamic mode and use Record.selectNewLine(options), and then Record.setCurrentSublistValue(options) followed by Record.commitLine(options)
m
seems like I am confusing between many ways
b
I don't know why you want to avoid getLineCount
m
pls help me with only one way
I dont want
to avoid anything whichever is requried
b
use getLineCount to get the line that you will use with setSublistValue
m
do you mean like below var numLines = objRecord.getLineCount({ sublistId: 'customrecord333' }); rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord122', line: numLines, value: 'address add for demo' }) rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord123', line: numLines, value: 3 }) rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord120', line: numLines, value: 2 })
b
I think your record variable is named rec
not objRecord
m
as I am trying to use the POST method in script itself function post(context) { doValidation([context.recordtype], ['recordtype'], 'POST'); var rec = record.create({ type: context.recordtype }); for (var fldName in context) if (context.hasOwnProperty(fldName)) if (fldName !== 'recordtype') rec.setValue(fldName, context[fldName]); var recordId = rec.save(); return String(recordId); }
here rec is the record
b
then what is objRecord
m
opps my bad
below is the whole function for POST. Please verify function post(context) { doValidation([context.recordtype], ['recordtype'], 'POST'); var rec = record.create({ type: context.recordtype }); for (var fldName in context) if (context.hasOwnProperty(fldName)) if (fldName !== 'recordtype') rec.setValue(fldName, context[fldName]); var recordId = rec.save(); var numLines = rec.getLineCount({ sublistId: 'customrecord333' }); rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord122', line: numLines, value: 'address add for demo' }) rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord123', line: numLines, value: 3 }) rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord120', line: numLines, value: 2 }) return String(recordId); }
b
onto the sublistId
the sublistId should not be the same as the id on the record type
the help topic above shows how to find the sublist id
its based on the field id of whatever field is used to establish the parent / child relationship
m
means it should be "recmachcustomrecord333"?
b
the id of the custom record type is not what you are looking for
you want the id of the field with the parent checkbox marked
m
message has been deleted
what should it be?
message has been deleted
I think these are only two screens involved inthis. if you can help me to finalize it. as it seems becoming more confusing.
b
there is a list of fields on the
CloudConnect Service custom record type
click on each field and find the one with the parent field marked
add recmach to the id of the field
m
I clicked on Status marked red
and it redirects me to
b
record is parent is not marked, its not that one
m
I am not sure what r u saying?
do you mean
I think it becomes very long conversation without any result till now
b
its a long conversation since you wanted to do an advanced customization without knowing how to do the basic version
its why i directed you to working with regular sublists
m
batt, I am not expert in suitescript. I have one solution to implement. You are the expert, whatever you will advice I will do accordingly. I appreciate your efforts, and understand even it is long conversation for you as well. but at the same time, I am getting confused at some places. so thats why it seems stuck. If want any screenshot/information then pls let me know, I will provide you.
you can advice me whatever the way you sense correct. I will follow that, there is no issue with it.
b
you are looking for the field with
Record is Parent
set
m
Ok pls reguide me
we have var numLines = rec.getLineCount({ sublistId: 'customrecord333' }); rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord122', line: numLines, value: 'address add for demo' })
you was saying to change sublistid
which one should I change 1st or second one?
I think we are close to solution but moved to some other direction in middle. pls confirm the corrections, so we can reach to result
b
you will have to change all sublist ids
m
you mean to say? rec.setSublistValue({ sublistId: 'customrecord333', fieldId: 'custrecord122', line: lineNum, value: 'address add for demo' })
b
customrecord333 is the record id of the custom record
you want the sublistId to be the id of the sublist
the sublist id of a custom child sublist is the id of the field that has the
Record is Parent
field set
so you need to find that field
m
I am thinking which section can I find it?
where will I find sublist id? Record Types / Custom Record Type / something else?
b
fields list on the cloudconnect circuits custom record type
m
are you saying to use these ids?
b
you will be using one of them
m
Type custrecord123 Address custrecord122 Type custrecord123
but this seems to be field id
b
correct
custom child sublists have a sublist id derived from a field id
and how you figure out the sublist id by finding the parent field
m
it is saying to prefix "recmach" in front of id?
b
Copy code
The New Customer field (internal ID: custrecord111) is the parent field for the fixed assets records that appear as children on customer records. Hence, the internal ID for the custom child Fixed Assets sublist on customer records is recmachcustrecord111.
m
rec.setSublistValue({ sublistId: 'recmachcustrecord122', fieldId: 'custrecord122', line: lineNum, value: 'address add for demo' })
is it the way?
b
customrecord333 is not a field id
m
pls recheck my typo mistake
b
is
custrecord122
the field with the`record is parent` field set
m
message has been deleted
this is after changes. Please verify function post(context) { doValidation([context.recordtype], ['recordtype'], 'POST'); var rec = record.create({ type: context.recordtype }); for (var fldName in context) if (context.hasOwnProperty(fldName)) if (fldName !== 'recordtype') rec.setValue(fldName, context[fldName]); var recordId = rec.save(); var lineNum = rec.getLineCount({ sublistId: 'customrecord333' }); rec.setSublistValue({ sublistId: 'recmachcustrecord122', fieldId: 'custrecord122', line: lineNum, value: 'address add for demo' }) rec.setSublistValue({ sublistId: 'recmachcustrecord123', fieldId: 'custrecord123', line: lineNum, value: 3 }) rec.setSublistValue({ sublistId: 'recmachcustrecord120', fieldId: 'custrecord120', line: lineNum, value: 2 }) return String(recordId); }
b
custrecord122 is the address field. Click the address link to go to its custom field page
check if the
record is parent
field is set, if not, keep looking at the other fields
m
message has been deleted
record is not parent
ok let me check again
this is parent
message has been deleted
should I user its id like? recmachcustrecord121
b
yes
m
function post(context) { doValidation([context.recordtype], ['recordtype'], 'POST'); var rec = record.create({ type: context.recordtype }); for (var fldName in context) if (context.hasOwnProperty(fldName)) if (fldName !== 'recordtype') rec.setValue(fldName, context[fldName]); var recordId = rec.save(); var lineNum = rec.getLineCount({ sublistId: 'customrecord333' }); rec.setSublistValue({ sublistId: 'recmachcustrecord121', fieldId: 'custrecord122', line: lineNum, value: 'address add for demo' }) rec.setSublistValue({ sublistId: 'recmachcustrecord121', fieldId: 'custrecord123', line: lineNum, value: 3 }) rec.setSublistValue({ sublistId: 'recmachcustrecord121', fieldId: 'custrecord120', line: lineNum, value: 2 }) return String(recordId); }
kindly confirm
b
Copy code
var recordId = rec.save();
should occur after the sublist code
Copy code
var lineNum = rec.getLineCount({
    sublistId: "customrecord333"
  });
still has the wrong sublistId
m
function post(context) { doValidation([context.recordtype], ['recordtype'], 'POST'); var rec = record.create({ type: context.recordtype }); for (var fldName in context) if (context.hasOwnProperty(fldName)) if (fldName !== 'recordtype') rec.setValue(fldName, context[fldName]); var lineNum = rec.getLineCount({ sublistId: 'recmachcustrecord121' }); rec.setSublistValue({ sublistId: 'recmachcustrecord121', fieldId: 'custrecord122', line: lineNum, value: 'address add for demo' }) rec.setSublistValue({ sublistId: 'recmachcustrecord121', fieldId: 'custrecord123', line: lineNum, value: 3 }) rec.setSublistValue({ sublistId: 'recmachcustrecord121', fieldId: 'custrecord120', line: lineNum, value: 2 }) var recordId = rec.save(); return String(recordId); }
is it good?
b
give it a try
m
ok
wow it worked. ah it was worth 🙂 thankyou batt.
I still need to customize this code. but still I hope now it will work for me.
I know I got irritated inbetween as it got long conversation. But I really appreciate your patience as well. and thankyou for help.