resolve()
The resolve() function (client-side and server-side) resolves a string containing resolve expressions, for example, '{Q/A}-XXX-{Q1/A2}'. You can use the calc() function to perform calculations on numbers returned by resolve expressions. For more information about resolve expressions, see Obtaining Answer Data with Resolve Expressions.
Syntax
Use this syntax for the resolve() function:
resolve(resolveExpression, enableStrictMode, customErrorMessage);
See detailed information about the syntax for each parameter:
nresolve('{QUESTION_CODE/ANSWER_CODE}', true | false, 'Custom error message');
Return Value
The resolve() function returns a string containing the resolved value, including empty strings. If enableStrictMode is set true, it returns null or the custom error message when one ore multiple resolve expressions return an empty string.
Parameters
The resolveExpression parameter is required.
The resolve() function accepts the following parameters:
-
resolveExpression(string) - 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- Iftrue, the function returnsnullor the custom error message when the result is an empty string for one or multiple resolve expressions. -
customErrorMessage(string) - A custom error message to display when the result is an empty string. This parameter is available only when theenableStrictModeparameter is set totrue.
Examples
The following examples show how to use the resolve() function.
Resolving a Value
This example resolves the value of the SOLE/ROLECENTER predefined answer.
let resolvedValue = resolve('{SOLE/ROLECENTER}');
console.log(resolvedValue);
Handling an Error with a Custom Message
This example provides a custom error message if the result is an empty string.
let resolvedValue = resolve('{DESK_TYPE/A1000}', true, 'Issues when resolving the value');
console.log(resolvedValue);
Performing Calculations When Resolving
This example performs calculations by combining the resolve() and calc() functions. The code resolves each internal reference, then evaluates the arithmetic expression. For more information about the calc() function, see Performing Calculations on Numbers Returned by Resolve Expressions.
let resolvedValue = resolve('calc({DESK/QTY} * {DESK/PRICE})');
console.log(resolvedValue);