"nlapiTriggerWorkflow" is not defined - Oracle Netsuite - netsuite

I tried to trigger a workflow programatically,
nlapiTriggerWorkflow(recType, recId, workflowId, actionId, stateId)
But I am getting,
"nlapiTriggerWorkflow" is not defined
both in console and in script debugger. Why do I get this error?

The issue is that nlapiTriggerWorkflow is server side only. If you want to trigger a workflow client side you can add a button to the preceding work flow step (see the docs) and trigger your workflow from that.

Maybe this is happening because you are trying to use Suitescript 1.0 API in Suitescript 2.0
If you are using Suitescript 2.0 (or if it is feasible to switch to Suitescript 2.0), you can try this -
var workflowInstanceId = workflow.trigger({
recordType: 'salesorder',
recordId: 1234,
workflowId: 'custworkflow_name',
defaultValues: p
actionId: workflowaction25
});
In case of issues, just search for workflow.trigger(options) in the SuiteAnswers.
Let me know.

Related

SDD Payment via Automated Action (Odoo v13)

Unfortunately Odoo has removed the automatic SSD payment from v12 to v13, which is crucial for me. Therefore I try to reproduce the behavior via an automated action and came quite far I guess.
I created an Automated Action that watches all invoices in draft and runs a python code if the invoice is set from draft to not draft. But unfortunately I get an error as soon as I try to post an invoice:
"Database fetch misses ids (('10',)) and has extra ids ((10,)), may be caused by a type incoherence in a previous request"
As far as I know this is related to type transformation, but as I am new to python & odoo, I am not sure how to transform the odoo datatypes correctly. Does anyone have a hint?
Here's the python code that should be executed:
payment = env['account.payment'].create({
'payment_method_id' : '6',
'partner_id': record.partner_id.id,
'journal_id' : '10',
'amount' : record.amount_residual
})
The ids are double checked and link to the correct entries:
payment_method_id '6' = my bank account
journal_id '10' = SDD Payment
Below please find the current domain applied to the Automated Action.
Any hints or help is much appreciated!
Many thanks.
Best regards,
Christian
CBfac
On the many2one field you have to assign the ID.
Code Correction:
payment = env['account.payment'].create({
'payment_method_id' : 6,
'partner_id': record.partner_id.id,
'journal_id' : 10,
'amount' : record.amount_residual
})
For everyone who needs automatic SDD payments in Odoo v13, here's the Automated Action that works for me (one more, thanks #Dipen Sah for your assistance):
Modell: account.move
Trigger: on update
Action: Execute python code
Domain (before update):
["&","&","&","&",["sdd_paying_mandate_id","=",False],["partner_id.sdd_mandate_ids","!=",False],["type","=","out_invoice"],["invoice_payment_state","=","not_paid"],["state","=","draft"]]
Domain (after update):
["&","&","&","&",["sdd_paying_mandate_id","=",False],["partner_id.sdd_mandate_ids","!=",False],["type","=","out_invoice"],["invoice_payment_state","=","not_paid"],["state","!=","draft"]]
Python code to execute:
payment = env['account.payment'].create({
#'name' : env['ir.sequence'].next_by_code('account.payment.customer.invoice'),
#'payment_type': 'inbound',
#'partner_type' : 'customer',
'payment_method_id' : 6,
'partner_id': record.partner_id.id,
'journal_id' : 10,
'amount' : record.amount_residual}).post()
You have to upate the journal and payment_method ids within the python code to match your IDs in order to get the action running properly.
Any improvements and/or feedback are welcome.
Best regards,
Christian

INVALID_RECORD_TYPE when voiding CHECK in Netsuite using Suitescript 2.0?

I'm trying to void transactions via script. It's working for all the other transactions except for check record and I can't figure out why. I'm getting the INVALID_RECORD_TYPE error.
Here's a sample code I am using.
var id = transaction.void({
type: 'check',
id: 25
});
Thanks.
Please check Setup > Accounting > Accounting Preferences > General: VOID TRANSACTIONS USING REVERSING JOURNALS.
If the preference is not checked, the Void button does not appear in checks and you get the invalid record type error.
Please check the Field Level help of the preference for details. You will need to toggle the preference (using N/config) before calling transaction.void on types that are not covered by your account setting.
You must Reversing Journal
and then this:
var checkId= transaction.void({
type: transaction.Type.CHECK,
id: 25
});

Is there an automated method for forcing an open/save in Netsuite

Is there an automated method for forcing an open/save on a Netsuite sales order. This will trigger an update on the value available to ship.
There are lots of options to do this assuming you already have the script and logic for updating the whatever you want to update.
You can have a scheduled script that will run and simply load your order and submit it or have a user event script deployed on a transaction related to the order or items in the order.
SuiteScript 1.0
var record = nlapiLoadRecord('salesorder', idSo);
var idRecord = nlapiSubmitRecord(record)
SuiteScript 2.0
var objRecord = record.load({
type: record.Type.SALES_ORDER,
id: idSo });
var recordId = objRecord.save();
With the codes above you can simply add your logic and you are good to go.

update customer custom fields from SCA or SSP

I'm trying to update a custom entity field during registration in an SCA app.
the published Netsuite docs indicate I should be able to call:
var webStore = session.getSiteSettings(['displayname', 'id']);
customer = session.getCustomer();
customer.updateProfile({
internalid: internalid,
customfields: {
custentity_registered_site: webstore.id
}
});
but this throws the ever helpful UNEXPECTED_ERROR
Has anyone had this working for custom fields? I am doing this just after registration so that may be the issue though I can get a valid customer internalid. Any luck with alternate syntax of some sort?
Eventually was able to get NS support to give me their internal stack trace.
The issue has to do with some internals from the Rhino Javascript engine that NS uses.
Basically the value returned from the NS API was returning a string like value and NS was not following the 2014 recommendation on its use and was failing in the underlying Java code. So the fix was simple but so frustrating:
var webStore = session.getSiteSettings(['displayname', 'id']);
customer = session.getCustomer();
customer.updateProfile({
internalid: internalid,
customfields: {
custentity_registered_site: webstore.id.toString()
}
});
Hope this helps someone.

How can I clear an external ID on a record in NetSuite?

I need to clear/reset the external ID on a record in NetSuite, but nothing I do is working.
Some of the InventoryItem records are incorrectly mapped to records in another system. I have an application that can sync up the two systems, but I need to clear NetSuite's external IDs first.
Responses don't really need to be SOAP-specific. If you know how to do it with some specific NetSuite/SuiteTalk client, that might point me in the right direction.
What I've Tried
First up, I tried using the nullFieldList... but maybe it doesn't work because externalId is an attribute, not an element?
<messages:update>
<messages:record internalId="7777" xsi:type="accounting:InventoryItem">
<core:nullFieldList xsi:type="core:NullField">
<core:name>externalId</core:name>
</core:nullFieldList>
</messages:record>
</messages:update>
The external ID is just a string, so I tried just setting it to blank. Didn't work either.
<messages:update>
<messages:record internalId="7777" xsi:type="accounting:InventoryItem">
<accounting:externalId></accounting:externalId>
</messages:record>
</messages:update>
I even tried setting the external ID to 0, but I get back a "not unique identifier" error
<messages:update>
<messages:record internalId="7777" xsi:type="accounting:InventoryItem">
<accounting:externalId>0</accounting:externalId>
</messages:record>
</messages:update>
Other Info
I'm using NetSuite's SOAP API v.2013_1
When I say "it doesn't work", I mean: after I do the update, I get a success response similar to the following:
<readResponse>
<platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2013_1.platform.webservices.netsuite.com"/>
<record internalId="7777" externalId="42" xsi:type="listAcct:InventoryItem" xmlns:listAcct="urn:accounting_2013_1.lists.webservices.netsuite.com">
<!-- snip -->
</record>
</readResponse>
If you are using scripts in netsuite you can run a scheduled script to clear records in NS by loading each record and setting the externalid to '' using the following simple code:
var rec= nlapiLoadRecord(type,id);
rec.setFieldValue('externalid','');
nlapiSubmitRecord(rec);
This seemed to work for me in my enviornment which was on 2015.2.
Unfortunately my understanding is that once you set an externalid you cannot clear it, you can set it to another value, but not back to null. I have experienced this both using SuiteScript as well as a Boomi process that uses the 2014.1 endpoint. This may have changed in the recent releases, as I have not tried it recently with SuiteScript nor with a newer endpoint.
You can eliminate the externalId on a record once it's been set. Here's an example using the NetSuite gem:
ns_customer = NetSuite::Records::Customer.get external_id: 'ext_id'
ns_customer.external_id = ''
ns_customer.update
Here's the corresponding XML for update:
<env:Body>
<platformMsgs:update>
<platformMsgs:record xsi:type="listRel:Customer" platformMsgs:internalId="199113" platformMsgs:externalId=""/>
</platformMsgs:update>
</env:Body>
I have had to attempt this before as well. I know the pains you describe. I ended up putting a "-" in front of my external ID to unlink it between my systems. You can do this in SOAP or even as a simple one time csv upload. As it was one time, I did csv.

Resources