```const fulfillment = context.newRecord; const fu...
# suitescript
k
Copy code
const fulfillment = context.newRecord;
const fulfillmentId = fulfillment.getValue("id");
    
const createdFrom = fulfillment.getValue("createdfrom");
Hi all, how can i make sure the item fulfillment is created from sales order only, and not other record such as Transfer order
Thought of an Alternative solution.
Copy code
const fulfillment = context.newRecord;
    const fulfillmentId = fulfillment.getValue("id");

    const createdFrom = fulfillment.getText("createdfrom");
    //If createdFrom include "Transfer Order" then return
    if (createdFrom.includes("Transfer Order")) {
      return {
        status: "success",
        message: "Not Valid Type of Sales Order",
      };
    }
m
That might break if the transaction name is changed to something else. It would be safer to get the ID and run a lookup to get transaction type
💯 1
k
ah gotcha, do you mean do a search function? Before I was trying to do a record.load for the information, then get the type from there but i need to specify type
m
You don't need to lead the record. You can use
search.lookupFields
Also, you might want to reverse your check condition and look at if the created from type is a Sales Order, because there may be other transaction types you also want to exclude. For example, I believe you can create a fulfilment from a vendor RA.
k
I see, i revamped the logic to this
Copy code
const fulfillment = context.newRecord;
    const fulfillmentId = fulfillment.getValue("id");

    const createdFrom = fulfillment.getText("createdfrom");
    log.debug("createdFrom", createdFrom);
    if (createdFrom.includes("Sales Order")) {
      try {
        createAutoCashSale(fulfillmentId as string);
        return;
      } catch (err) {
        log.debug("error", err);
        err.toString = function () {
          return err.message;
        };
        handleError(err, fulfillmentId as string);
        throw err;
      }
    }
  }
m
I still recommend looking up the record type rather than relying on text field that could be renamed
💯 2
k
ok
n
Nah
if (createdFrom !== '') { createdFromRecType = search.lookupFields({ type: search.Type.TRANSACTION, id: createdFrom, columns: 'recordtype' }).recordtype; } let isCreatedFromPO = (createdFromRecType === record.Type.PURCHASE_ORDER); let isCreatedFromRA = (createdFromRecType === record.Type.RETURN_AUTHORIZATION); let isCreatedFromTO = (createdFromRecType === record.Type.TRANSFER_ORDER); if(!(isCreatedFromPO || isCreatedFromRA ||isCreatedFromTO)){ return true; }
something like that
Don't be using text based values from the field
@Ken See the above
a
I assume you are doing this in the
afterSubmit
entry point, because you are not going to have a Fulfillment ID on
beforeSubmit
on
CRETE
event. Then you don't need:
fulfillment.getValue("id");
Which to be honest looks like autogenerated(ChatGPT?). The ID would be available in the entry point context:
context.newRecord.id
chatgpt ai 1
n
@alien4u for a moment I thought you were suggesting my code was from chatgpt 🤣
😂 1