Not allowing duplicate standard templates from being submitted

Darlene York
Tera Contributor

Im trying to create a business rule that would prevent someone from submitting a duplicate standard change template.  Here is my logic. But it isn't working.  

 

When submitting a change proposal on the std_change_proposal table want to do a check on the "short_description" field against the std_change_record_producer table "name" field to see if there is an existing template. If there is abort the submission.

 

Table:  std_change_proposal

I did an before business rule on insert

 

(function executeRule(current, gsn, gs) {
    // Query the std_change_record_producer table
    var recordProducerGR = new GlideRecord('std_change_record_producer');
    recordProducerGR.addQuery('name', current.short_description);
    recordProducerGR.query();

    if (recordProducerGR.next()) {
        gs.addErrorMessage('A template with this name already exists in the Standard Change Record Producer table.');
        current.setAbortAction(true); // Prevents the record from being inserted
    }
})();
 
thank you
3 REPLIES 3

Swapna Abburi
Mega Sage
Mega Sage

Hi @Darlene York 

The business rule looks good. If you are comparing Template name from existing standard change templates with Template Description on new template, the business rule should work as expected.

Humm, thank you, I cant figure out why its not working.

Hi @Darlene York ,

 

Have you tried checking logs for "short_description" value, whether it is populating correctly or not.

 

If you have checked the logs, then next step is to try creating some real world example to test the BR. Create same record on both the table with same name on "std_change_record_producer" as same as name while creating new standard change template on table "std_change_proposal" keep same short description value.

 

Try to use current.getDisplayValue("short_description")