nresolve()

The nresolve() function (client-side and server-side) resolves the numeric value from a resolve expression {Q/A}. This function is useful to verify that the resolved data is a number and handle cases in which the value may not contain a number. You can also specify a custom error message. The calc() function can be used to perform calculations on numbers returned by resolve expressions. For more information about resolve expressions, see Obtaining Answer Data with Resolve Expressions.

Note:

Unlike resolve() and sresolve(), this function only accepts numbers as additional characters in the string that contains the resolve expressions. A string like '{Q/A}-XXX-{Q1/A2}' can't be processed using nresolve().

Syntax

The general syntax for the nresolve() function is the following:

            nresolve(resolveExpression, enableStrictMode, customErrorMessage); 

          

See detailed info about the syntax for each parameter:

            nresolve('{QUESTION_CODE/ANSWER_CODE}', true | false, 'Custom error message'); 

          

Return Value

The nresolve() function returns a string containing the numeric value from the resolved question and answer combination. If the function can't resolve a number, it returns the predefined error string invalid.

If enableStrictMode is true, the function returns invalid or the custom error message when one ore multiple resolve expressions return an empty string.

Parameters

Note:

The resolveExpression parameter is required.

The nresolve() function accepts the following parameters:

  • resolveExpression (string) - Specifies the resolve expression in the format {QUESTION_CODE/ANSWER_CODE}. You can find the codes in the Code field on the question and answer records.

  • enableStrictMode - If true, the function returns invalid or the custom error message when one or more resolve expressions return an empty string.

  • customErrorMessage (string) - Specifies a custom error message displayed when one or more resolve expressions return an empty string. This parameter is available only when the allowCustomError parameter is set to true.

Examples

The following examples show how to use the nresolve() function.

Resolving a Numeric Value

This example extracts a numeric value from the predefined associated with the configurable item quantity used in the resolve expression.

              let resolvedValue = nresolve('{SOLE/QUANTITY}');
console.log(resolvedValue); 

            

If the function successfully resolve the numeric value, it returns the value as a string. The resulting output may look like this:

              1 

            

Handling an Error for a Non-Numeric Value

This examples shows how the nresolve() function behaves when the resolve expression doesn't resolve to a number.

              let resolvedValue = nresolve('{SOLE/ROLECENTER}');
console.log(resolvedValue); 

            

The value in the predefined answer for the role center is an alphabetical string. Since the resolved value isn't numeric, the function returns the predefined error string:

              invalid 

            

Related Topics

General Notices