Class: ScriptMessage
An immutable parsed SCRIPT message: routing header, the typed body, and any non-fatal warnings raised while parsing. Construct via "./parse".parseScript: instances are deeply frozen.
Example
const msg = parseScript(xml);
msg.header.messageId;
msg.asNewRx()?.medication?.description;
Constructors
Constructor
new ScriptMessage(
init):ScriptMessage
Parameters
init
Pre-extracted header, body, warnings, and optional profile.
body
header
profile?
warnings
readonly NcpdpScriptWarning[]
Returns
ScriptMessage
Properties
body
readonlybody:ScriptBody
The typed transaction body.
header
readonlyheader:ScriptHeader
Routing/correlation header fields.
profile?
readonlyoptionalprofile?:NcpdpProfile
The trading-partner profile in effect for this parse: either passed
explicitly via parseScript's options.profile or resolved from the
process-scoped default. Present only when a profile applied; attribution
only (v1 profiles never alter the parse).
warnings
readonlywarnings: readonlyNcpdpScriptWarning[]
Non-fatal warnings, in the order raised.
Accessors
correlatesTo
Get Signature
get correlatesTo():
string|undefined
The identifier of the message this one answers (<RelatesToMessageID>), or
undefined. The correlation key that ties a response back to its request.
Example
parseScript(responseXml).correlatesTo; // the request's MessageID
Returns
string | undefined
The correlated message id, or undefined.
disposition
Get Signature
get disposition():
ResponseDisposition|undefined
The disposition of this message when it is a response transaction
(<Status>/<Error>/<Verify>), else undefined. Derived only from the
body kind: an <Error> is always "error" and is never read as a
success.
Example
parseScript(xml).disposition; // "success" | "error" | "verify" | undefined
Returns
ResponseDisposition | undefined
The ResponseDisposition, or undefined for a request /
unsupported transaction.
Methods
asError()
asError():
ErrorBody|undefined
The ErrorBody when this message is an <Error> response, else
undefined.
Returns
ErrorBody | undefined
The Error body, or undefined.
Example
parseScript(xml).asError()?.code;
asLifecycleRequest()
asLifecycleRequest():
LifecycleRequest|undefined
The LifecycleRequest body when this message is a renewal/change/cancel
request (RxRenewalRequest/RxChangeRequest/CancelRx), else undefined.
Returns
LifecycleRequest | undefined
The lifecycle request body, or undefined.
Example
parseScript(xml).asLifecycleRequest()?.medicationPrescribed?.description;
asLifecycleResponse()
asLifecycleResponse():
LifecycleResponse|undefined
The LifecycleResponse body when this message is a renewal/change/cancel
response (RxRenewalResponse/RxChangeResponse/CancelRxResponse), else
undefined.
Returns
LifecycleResponse | undefined
The lifecycle response body, or undefined.
Example
parseScript(xml).asLifecycleResponse()?.outcome; // "approved" | "denied" | …
asNewRx()
asNewRx():
NewRx|undefined
The NewRx body when this message is a NewRx, else undefined.
Returns
NewRx | undefined
The NewRx body, or undefined.
Example
const rx = parseScript(xml).asNewRx();
rx?.medication?.description;
asStatus()
asStatus():
StatusBody|undefined
The StatusBody when this message is a <Status> response, else
undefined.
Returns
StatusBody | undefined
The Status body, or undefined.
Example
parseScript(xml).asStatus()?.code;
asVerify()
asVerify():
VerifyBody|undefined
The VerifyBody when this message is a <Verify> response, else
undefined.
Returns
VerifyBody | undefined
The Verify body, or undefined.
Example
parseScript(xml).asVerify()?.code;
toString()
toString():
string
Serialize this message back to canonical NCPDP SCRIPT XML. Equivalent to "./serialize".serializeScript; only the modeled fields are emitted, so the result is canonical (idempotent under re-parse) rather than byte-identical to any original input.
Returns
string
The canonical SCRIPT XML string.
Example
parseScript(raw).toString(); // canonical XML