Hi <@U29QCJQF3> now in the right channel :wink: Ma...
# suitescript
i
Hi @michoel now in the right channel 😉 May I bother you /someone else with another quick pointer. I'll process address and contacts directly in PUT/POST as you recommend, the question: 1. system.netsuite.com/app/help/helpcenter.nl?fid=section_1545295601.html shows a patch method with pure JS objects<< Would this work at all? Tried briefly with no results. 2. Process as usual (something on the lines of -this is a working script btw just for reference-) :
function setAddress(context, address) {
var CR = context.currentRecord;
var addSubRecord = CR.getCurrentSublistSubrecord({
sublistId: "addressbook",
fieldId: "addressbookaddress"
});
var currentAddressCount = CR.getLineCount({
sublistId: "addressbook"
});
var nl = null;
if (currentAddressCount === 0) {
CR.selectNewLine({
sublistId: "addressbook"
});
} else {
CR.selectLine({
sublistId: "addressbook",
line: 0
});
}
var subrecord = nlapiEditCurrentLineItemSubrecord(
"addressbook",
"addressbookaddress"
);
if (subrecord == null)
subrecord = nlapiCreateCurrentLineItemSubrecord(
"addressbook",
"addressbookaddress"
);
var code = countryCodes[address.country];
if (code) {
subrecord.setFieldValue("country", code);
}
subrecord.setFieldValue("city", address.city);
subrecord.setFieldValue("zip", address.zip);
subrecord.setFieldValue("state", address.state);
subrecord.setFieldValue("addressee", "");
subrecord.commit();
nlapiCommitLineItem("addressbook");
// **** 2
}
Sorry for the long post,
b
Sounds like you are talking about a restlet, so there is no patch support
Dont confuse suitescript with suitetalk
As for your samples, one of them is a suitescript 2 client script
Not sure what its supposed to do
The second example is a suitescript 1 example that sets address fields
Not sure if its a client script or a user event script
i
Hi @battk Yes, perhaps I was just dreaming that restlets will have patch support somehow 🙂 For the samples, you're also right. I usually develop on Suitescript 2 but after failing to do the address scripting I was told by a consultant at the time, that it was broken in 2 and have to do in v 1 to succeed. That was the resulting code. Which inter-operates nicely with the v2
b
suitescript 2 subrecord support is supported on serverside script
shouldnt be an issue if you are writing a restlet
i
Ah good to know, this time the code is for serverside so could be done.
Beyond having all in the same version, any advantage of rewriting the function?
b
you dont have a choice, you cant mix suitescript 2 and 1 in serverscript
pick one or the other, no mixing
i
Sounds like lots of "fun" is on my way 😛
Any good source of info?
i
Thanks!
That was actually easy...
function setAddress(rec, address) {
var subrecord = rec.getSublistSubrecord({
sublistId: "addressbook",
fieldId: "addressbookaddress",
line: 0
});
subrecord.setValue("addr1", address.addr1);
subrecord.setValue("city", address.city);
subrecord.setValue("state", address.state);
subrecord.setValue("zip", address.zip);
// if (code) {
subrecord.setValue("country", address.country);
return;
}
Sure now have to verify update rules, etc but not that bad 🙂
b
although that should work , you may want to use the documented form of setValue
Copy code
subrecord.setValue({fieldId: "addr1", value: address.addr1});
i
that's great, it's working well.. I'll clean this up and work tomorrow on Sales Team and Contacts. Hopefully works equally well 🙂 Thanks a lot @battk
Hi again, Lead addresses was easily done (thanks for that), but I'm having issues with Sales Team and Contacts, Can they be edited as subrecords? or is it better to load/add a full record and link them? I think I have the sublistId from the record browser, but can't figure out the fieldId, according to the help it should be 'The field with summary type' but I have none of those on those two fields... Any idea or pointers in the right direction?
m
Contacts are a seperate record. You have to save the lead, then create the contact record and then attach it to the lead.
Copy code
var primaryContactRecord = record.create({ type: record.Type.CONTACT });
primaryContactRecord.setValue({ fieldId: 'firstname', value: "Joe") });
primaryContactRecord.setValue({ fieldId: 'lastname', value: "Shmoe") });
primaryContactRecord.setValue({ fieldId: 'email', value: "<mailto:joe@shmoe.com|joe@shmoe.com>"});
primaryContactRecord.setValue({ fieldId: 'phone', value: "123 456 789"});
primaryContactRecord.setValue({ fieldId: 'company', value: leasRecordId });
var primaryContactId = primaryContactRecord.save();

record.attach({
  record: { type: record.Type.CONTACT, id: primaryContactId },
  to: { type: type, id: leadRecordId },
  attributes: { role: CONTACT_ROLES.PRIMARY_CONTACT },
});
Excuse the formatting, I'm on mobile..
i
Thanks @michoel That explains it all 🙂
Any idea on Sales Team, beyond Sales Rep, we use a list of Sales people with different contributions, etc..
m
Personally I've only used sales rep, so I don't have experience but I imagine it's a sublist. You might want to post a seperate question in the channel