CIS-ITSM · Question #32
The current status of a problem record is tracked in the State field. Each state has a label, value and constant. This example is for Fix in Progress state: Your customer wants to add a prerequisite…
The correct answer is C. ProblemState.STATES.FIX_IN_PROGRESS. In ServiceNow scripting, using symbolic constants instead of raw values is the best practice for maintainability and readability.
Question
The current status of a problem record is tracked in the State field. Each state has a label, value and constant. This example is for Fix in Progress state:
Your customer wants to add a prerequisite for moving out of the Fix in Progress state. When you update the script include which value is better to use in the script?
Options
- A104
- B"Fix in Progress"
- CProblemState.STATES.FIX_IN_PROGRESS
- D104.ProblemState.STATES.FIX_IN_PROGRESS
How the community answered
(26 responses)- B4% (1)
- C96% (25)
Why each option
In ServiceNow scripting, using symbolic constants instead of raw values is the best practice for maintainability and readability.
Using the raw integer 104 is a magic number that is brittle - it has no self-documenting meaning and breaks if the value is ever reassigned in the State field.
Using the string 'Fix in Progress' references the display label, which can be localized or renamed by an admin without changing the underlying value, making the condition unreliable.
ProblemState.STATES.FIX_IN_PROGRESS is a symbolic constant defined in the Problem State script include, which makes the script resilient to display label changes and avoids hardcoded magic numbers. Using constants ensures that if the underlying value ever changes, scripts referencing the constant update automatically without code changes.
This is syntactically invalid - you cannot prefix a numeric literal with a dot-notation object reference in JavaScript.
Concept tested: ServiceNow script include symbolic constants best practice
Source: https://developer.servicenow.com/dev.do#!/guides/xanadu/now-platform/tpb-guide/best_practices_scripting
Topics
Community Discussion
No community discussion yet for this question.