how can i set the cost of an invoice line
# ask-stanley-ai
s
how can i set the cost of an invoice line
c
AI generated answer (using internal Slack threads):
To set the cost of an invoice line, you would need to use a script or workflow. Unfortunately, the cost field is not directly exposed in workflows, so you would need to use a Workflow Action Script to set the value of the cost field on the invoice line. Here is a sample Workflow Action Script that was shared in the threads:
Copy code
javascript
/**
 * @copyright 2023 <http://Carsales.com.au|Carsales.com.au>
 * @author Michoel Chaikin <michoel.chaikin@carsales.com.au>
 * @NApiVersion 2.1
 * @NScriptType WorkflowActionScript
 *
 * Workflow Action Script to set the value of any line level field on a workflow. The native Set Line Value workflow
 * action only supports specific sublists and fields.
 */
define(["N/runtime"], (runtime) => {
  var exports = {};

  /**
   * @param {import("N/types").EntryPoints.WorkflowAction.onActionContext } context
   */
  exports.onAction = function (context) {
    log.debug({ title: "=== WA Script Starting ===" });

    const script = runtime.getCurrentScript();

    const sublistId = script.getParameter({ name: "custscript_cs_setsublistvalue_sublist_id" });
    const fieldId = script.getParameter({ name: "custscript_cs_setsublistvalue_field_id" });
    const line = script.getParameter({ name: "custscript_cs_setsublistvalue_line" });
    const value = script.getParameter({ name: "custscript_cs_setsublistvalue_value" });

    log.debug({ title: "script parameters", details: JSON.stringify({ sublistId, fieldId, line, value }) });

    context.newRecord.selectLine({ sublistId, line });
    context.newRecord.setCurrentSublistValue({ sublistId, fieldId, value });
    context.newRecord.commitLine({ sublistId });

    log.debug({ title: "=== WA Script Complete ===" });
  };

  return exports;
});
This script allows you to set the value of any line level field on a workflow. You would need to set the parameters for the sublistId, fieldId, line, and value to match your specific needs. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.808843076
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.803061306
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.799418151
Please provide your feedback on this answer.