Coding suggestion on my below code. I was stuck at this point

Priyanka21
Tera Contributor
  • In the below code an I use sysid of the entity type market units directly in the code for checking the matchings. Is it comes under hard-coded? Will business team accept it or else do I need to get the sysid dynamically by querying the record. Pls suggest.

 

  1. var AllocationProfileValidationHelper = Class.create();
    AllocationProfileValidationHelper.prototype = {
    initialize: function() {},

    validateAllocationProfile: function(current) {
    var workplaceEntity = new GlideRecord('sn_wsd_core_workplace_entity');

    // Check if the workplace entity record exists
    if (!workplaceEntity.get(current.workplace_entity)) {
    gs.addErrorMessage("Invalid Workplace Entity.");
    return false;
    }

    var entityType = workplaceEntity.entity_type.toLowerCase();
    var allocationProfile = current.allocation_profile.toLowerCase();
    var isValid = true; // Assume validation is successful

    // Debugging information
    gs.info("Validation Check: Allocation Profile = " + allocationProfile + ", Entity Type = " + entityType);

    if (allocationProfile === 'owner') {
    // For 'Owner' profile, the workplace entity must be of type 'Market Unit'
    if (entityType !== 'fcffa877976e7554bf05b4221153af3b') {
    gs.addErrorMessage("Workplace Entity must be of type 'Market Unit' for 'Owner' profile.");
    gs.info("find if");
    isValid = false;
    }
    } else if (allocationProfile === 'tenant') {
    // For 'Tenant' profile, the workplace entity must NOT be of type 'Market Unit'
    if (entityType === 'fcffa877976e7554bf05b4221153af3b') {
    gs.addErrorMessage("Workplace Entity of type 'Market Unit' cannot be selected for 'Tenant' profile.");
    isValid = false;
    }
    }

    // Return the validation result
    return isValid;
    }
    }; 
1 REPLY 1

-O-
Kilo Patron
Kilo Patron

Yes, that is hard-coding. Program should not contain data.

Worst case scenario, move the sys_id into a property.

Best make user of a decision table that can be edited independently of code and that would describe the conditions for the selection to be valid.

As for business team accepting this, unless you mean something else to what I understand that to be, they are not qualified to judge the solution.