Courseiva

SNOW-CAD

Full exam simulation

1:30:00
1

Creating and customizing tables and data

medium

A developer created the business rule shown in the exhibit to auto-generate asset tags. However, when a new asset is created, sometimes the generated tag is a duplicate of an existing tag. What is the most likely cause?

Exhibit

Refer to the exhibit.

Table: u_custom_asset
Fields:
  u_asset_tag: string (max length 50)
  u_serial_number: string (max length 100)
  u_model: reference to cmdb_model
  u_cost: currency

Business rule: Before insert on u_custom_asset
Script:
(function executeRule(current, previous /*null when async*/) {

    if (!current.u_asset_tag) {
        var gr = new GlideRecord('u_custom_asset');
        gr.addQuery('u_asset_tag', 'CONTAINS', 'AST-');
        gr.orderByDesc('sys_created_on');
        gr.query();
        if (gr.next()) {
            var lastTag = gr.u_asset_tag.toString();
            var num = parseInt(lastTag.substring(4)) + 1;
            current.u_asset_tag = 'AST-' + num;
        } else {
            current.u_asset_tag = 'AST-1000';
        }
    }

})(current, previous);
0 of 180 answered