Question: I have an integration failing due to the...
# suitescript
n
Question: I have an integration failing due to the sales order (upsert) exceeding the customer credit limit. Although I understand that from a design standpoint it makes sense to have it fail - we don't want it to fail via the integration but only in the UI. Does anyone have any clue on how to bypass this for specific orders?
e
Is it an integration you wrote or is it managed/3rd party?
n
workato
so iPaaS in the middle
if the solution involves some scripting etc. though i don't have an issue with that
e
hmm, what about adding a script that runs before that integration script and increases customer limit if needed?
I suppose you probably don’t want to update the limit though.
n
yeah we wouldn't want to update it
unless we like temporarily update it and then set it back lol
w
Copy code
/**
@NApiVersion 2.x
@NScriptType UserEventScript
@NModuleScope SameAccount
 */
define(["N/record"], function(record) {
  function beforeSubmit(context) {
    // Get the current sales order record
    var currentRecord = context.newRecord;

    // Get the ID of the customer associated with the sales order
    var customerId = currentRecord.getValue({
      fieldId: "entity"
    });

    // Load the customer record
    var customerRecord = record.load({
      type: record.Type.CUSTOMER,
      id: customerId,
      isDynamic: true
    });

    // Get the current credit limit of the customer
    var currentCreditLimit = customerRecord.getValue({
      fieldId: "creditlimit"
    });

    // Check if the credit limit needs to be increased
    if (currentCreditLimit < 1000) {
      // Increase the credit limit to 1000
      customerRecord.setValue({
        fieldId: "creditlimit",
        value: 1000
      });

      // Save the updated customer record
      customerRecord.save();
    }
  }

  return {
    beforeSubmit: beforeSubmit
  };
});
😂 4
n
hahaha
i mean it could work
i wonder if you can just put it back after
w
Perhaps you could do that in aftersubmit.
You could also do that in workato, unless you are using the bulk-functions. Check credit limit, update if needed, create sales order, decrease limit if it was raised.
n
i could but then workato is tasked based and we're trying to streamline that part
but I guess I could do that
ok great so it looks like my options are to raise temporarily, create the order, lower it back
w
Isn't there asetting as well to either warn or prevent “overdrafts”?
Pretty sure there is one, I think it event might be personal (if Allowed)
message has been deleted
Sorry, but chatGPT is fun to play with
👍 1
Here's from the personal settings as well
n
interesting
i wonder if we can go through a user if they disable this