--- policy: /ce/ca/azure/savings-plan/utilization-below-threshold logic: /ce/ca/azure/savings-plan/utilization-below-threshold/prod.logic.yaml executionTime: 2026-09-22T15:06:45.966775996Z generationMs: 63 executionMs: 1275 rows: - id: gone match: true status: expected: DISAPPEARED actual: DISAPPEARED conditionIndex: expected: 99 actual: 99 conditionText: expected: isDisappeared(CA10Z1__disappearanceTime__c) actual: isDisappeared(CA10Z1__disappearanceTime__c) runtimeError: {} - id: missing-state match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 199 actual: 199 conditionText: expected: extract('CA10Z1__provisioningState__c').isEmpty() actual: extract('CA10Z1__provisioningState__c').isEmpty() runtimeError: {} - id: expired match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 299 actual: 299 conditionText: expected: extract('CA10Z1__provisioningState__c') != 'Succeeded' actual: extract('CA10Z1__provisioningState__c') != 'Succeeded' runtimeError: {} - id: fresh-incomplete match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 399 actual: 399 conditionText: expected: CA10Z1__CaAzureSavingsPlanUtilization__r.has(UNDETERMINED) actual: CA10Z1__CaAzureSavingsPlanUtilization__r.has(UNDETERMINED) runtimeError: {} - id: missing-usage-date match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 399 actual: 399 conditionText: expected: CA10Z1__CaAzureSavingsPlanUtilization__r.has(UNDETERMINED) actual: CA10Z1__CaAzureSavingsPlanUtilization__r.has(UNDETERMINED) runtimeError: {} - id: stale-incomplete match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 600 actual: 600 conditionText: expected: otherwise actual: otherwise runtimeError: {} - id: mixed-recent-periods match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 499 actual: 499 conditionText: expected: CA10Z1__CaAzureSavingsPlanUtilization__r.has(INCOMPLIANT) actual: CA10Z1__CaAzureSavingsPlanUtilization__r.has(INCOMPLIANT) runtimeError: {} - id: below match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 499 actual: 499 conditionText: expected: CA10Z1__CaAzureSavingsPlanUtilization__r.has(INCOMPLIANT) actual: CA10Z1__CaAzureSavingsPlanUtilization__r.has(INCOMPLIANT) runtimeError: {} - id: boundary match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 599 actual: 599 conditionText: expected: CA10Z1__CaAzureSavingsPlanUtilization__r.has(COMPLIANT) actual: CA10Z1__CaAzureSavingsPlanUtilization__r.has(COMPLIANT) runtimeError: {} usedFiles: - path: /ce/ca/azure/savings-plan/utilization-below-threshold/policy.yaml md5Hash: 2E2A1217422C7279D770608005116948 content: | --- names: full: "Azure Savings Plan utilization is below 80%" contextual: "Savings Plan utilization is below 80%" description: "Identify successfully provisioned Azure Savings Plans with utilization below 80% in the last 40 days." categories: - "COST" type: "COMPLIANCE_POLICY" frameworkMappings: - "/frameworks/cloudaware/cost-efficiency-and-optimization/resource-optimization" - path: /ce/ca/azure/savings-plan/utilization-below-threshold/prod.logic.yaml md5Hash: F2249CFCAFDBBB6F7F81603E4D919FAE content: | --- inputType: "CA10Z1__CaAzureSavingsPlan__c" testData: - file: "test-data.json" importExtracts: - file: "/types/CA10Z1__CaAzureSavingsPlan__c/object.extracts.yaml" conditions: - status: "UNDETERMINED" currentStateMessage: "The Savings Plan provisioning state is unavailable." check: IS_EMPTY: arg: EXTRACT: "CA10Z1__provisioningState__c" - status: "INAPPLICABLE" currentStateMessage: "The Savings Plan is not successfully provisioned." check: NOT_EQUAL: left: EXTRACT: "CA10Z1__provisioningState__c" right: TEXT: "Succeeded" - status: "UNDETERMINED" currentStateMessage: "A utilization record within the last 40 days has incomplete data." check: RELATED_LIST_HAS: status: "UNDETERMINED" relationshipName: "CA10Z1__CaAzureSavingsPlanUtilization__r" - status: "INCOMPLIANT" currentStateMessage: "Savings Plan utilization was below 80% within the last 40 days." remediationMessage: "Review recent utilization and adjust future Savings Plan commitment coverage if the shortfall is persistent." check: RELATED_LIST_HAS: status: "INCOMPLIANT" relationshipName: "CA10Z1__CaAzureSavingsPlanUtilization__r" - status: "COMPLIANT" currentStateMessage: "Savings Plan utilization met the 80% threshold throughout the available records from the last 40 days." check: RELATED_LIST_HAS: status: "COMPLIANT" relationshipName: "CA10Z1__CaAzureSavingsPlanUtilization__r" otherwise: status: "UNDETERMINED" currentStateMessage: "No complete Savings Plan utilization record is available within the last 40 days." relatedLists: - relationshipName: "CA10Z1__CaAzureSavingsPlanUtilization__r" importExtracts: - file: "/types/CA10Z1__CaAzureSavingsPlanUtilization__c/object.extracts.yaml" conditions: - status: "UNDETERMINED" currentStateMessage: "The utilization record's Usage Date is unavailable." check: IS_EMPTY: arg: EXTRACT: "CA10Z1__usageDate__c" - status: "INAPPLICABLE" currentStateMessage: "The utilization record is outside the 40-day reporting window." check: NOT: arg: IS_WITHIN_LAST_DAYS: offsetDays: 40 arg: EXTRACT: "CA10Z1__usageDate__c" - status: "UNDETERMINED" currentStateMessage: "The utilization record's average utilization is unavailable." check: IS_EMPTY: arg: EXTRACT: "CA10Z1__avgUtilizationPercentage__c" - status: "INCOMPLIANT" currentStateMessage: "Average utilization is below 80%." remediationMessage: "Review recent eligible usage and future commitment requirements." check: LESS_THAN: left: EXTRACT: "CA10Z1__avgUtilizationPercentage__c" right: NUMBER: 80.0 otherwise: status: "COMPLIANT" currentStateMessage: "Average utilization meets the 80% threshold." - path: /ce/ca/azure/savings-plan/utilization-below-threshold/test-data.json md5Hash: DB44D8F2AD88E2E2D551ECC75AF81078 content: |- [ { "expectedResult": { "status": "DISAPPEARED", "conditionIndex": "99", "conditionText": "isDisappeared(CA10Z1__disappearanceTime__c)", "runtimeError": null }, "context": { "snapshotTime": "2026-09-15T00:00:00Z" }, "Id": "gone", "RecordType": { "Id": "savings-plan" }, "RecordTypeId": "savings-plan", "CA10Z1__disappearanceTime__c": "2026-09-14T00:00:00Z", "CA10Z1__provisioningState__c": "Succeeded", "CA10Z1__CaAzureSavingsPlanUtilization__r": [] }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "199", "conditionText": "extract('CA10Z1__provisioningState__c').isEmpty()", "runtimeError": null }, "context": { "snapshotTime": "2026-09-15T00:00:00Z" }, "Id": "missing-state", "RecordType": { "Id": "savings-plan" }, "RecordTypeId": "savings-plan", "CA10Z1__disappearanceTime__c": null, "CA10Z1__provisioningState__c": "", "CA10Z1__CaAzureSavingsPlanUtilization__r": [] }, { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "299", "conditionText": "extract('CA10Z1__provisioningState__c') != 'Succeeded'", "runtimeError": null }, "context": { "snapshotTime": "2026-09-15T00:00:00Z" }, "Id": "expired", "RecordType": { "Id": "savings-plan" }, "RecordTypeId": "savings-plan", "CA10Z1__disappearanceTime__c": null, "CA10Z1__provisioningState__c": "Expired", "CA10Z1__CaAzureSavingsPlanUtilization__r": [] }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "399", "conditionText": "CA10Z1__CaAzureSavingsPlanUtilization__r.has(UNDETERMINED)", "runtimeError": null }, "context": { "snapshotTime": "2026-09-15T00:00:00Z" }, "Id": "fresh-incomplete", "RecordType": { "Id": "savings-plan" }, "RecordTypeId": "savings-plan", "CA10Z1__disappearanceTime__c": null, "CA10Z1__provisioningState__c": "Succeeded", "CA10Z1__CaAzureSavingsPlanUtilization__r": [ { "Id": "util-missing-average", "RecordType": { "Id": "utilization" }, "RecordTypeId": "utilization", "CA10Z1__disappearanceTime__c": null, "CA10Z1__benefit__c": "fresh-incomplete", "CA10Z1__usageDate__c": "2026-09-01", "CA10Z1__avgUtilizationPercentage__c": null } ] }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "399", "conditionText": "CA10Z1__CaAzureSavingsPlanUtilization__r.has(UNDETERMINED)", "runtimeError": null }, "context": { "snapshotTime": "2026-09-15T00:00:00Z" }, "Id": "missing-usage-date", "RecordType": { "Id": "savings-plan" }, "RecordTypeId": "savings-plan", "CA10Z1__disappearanceTime__c": null, "CA10Z1__provisioningState__c": "Succeeded", "CA10Z1__CaAzureSavingsPlanUtilization__r": [ { "Id": "util-missing-date", "RecordType": { "Id": "utilization" }, "RecordTypeId": "utilization", "CA10Z1__disappearanceTime__c": null, "CA10Z1__benefit__c": "missing-usage-date", "CA10Z1__usageDate__c": null, "CA10Z1__avgUtilizationPercentage__c": 50 } ] }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "600", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2026-09-15T00:00:00Z" }, "Id": "stale-incomplete", "RecordType": { "Id": "savings-plan" }, "RecordTypeId": "savings-plan", "CA10Z1__disappearanceTime__c": null, "CA10Z1__provisioningState__c": "Succeeded", "CA10Z1__CaAzureSavingsPlanUtilization__r": [ { "Id": "util-stale-missing-average", "RecordType": { "Id": "utilization" }, "RecordTypeId": "utilization", "CA10Z1__disappearanceTime__c": null, "CA10Z1__benefit__c": "stale-incomplete", "CA10Z1__usageDate__c": "2026-08-01", "CA10Z1__avgUtilizationPercentage__c": null } ] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "499", "conditionText": "CA10Z1__CaAzureSavingsPlanUtilization__r.has(INCOMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2026-09-05T00:00:00Z" }, "Id": "mixed-recent-periods", "RecordType": { "Id": "savings-plan" }, "RecordTypeId": "savings-plan", "CA10Z1__disappearanceTime__c": null, "CA10Z1__provisioningState__c": "Succeeded", "CA10Z1__CaAzureSavingsPlanUtilization__r": [ { "Id": "util-low", "RecordType": { "Id": "utilization" }, "RecordTypeId": "utilization", "CA10Z1__disappearanceTime__c": null, "CA10Z1__benefit__c": "mixed-recent-periods", "CA10Z1__usageDate__c": "2026-08-01", "CA10Z1__avgUtilizationPercentage__c": 70 }, { "Id": "util-high", "RecordType": { "Id": "utilization" }, "RecordTypeId": "utilization", "CA10Z1__disappearanceTime__c": null, "CA10Z1__benefit__c": "mixed-recent-periods", "CA10Z1__usageDate__c": "2026-09-01", "CA10Z1__avgUtilizationPercentage__c": 95 } ] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "499", "conditionText": "CA10Z1__CaAzureSavingsPlanUtilization__r.has(INCOMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2026-09-15T00:00:00Z" }, "Id": "below", "RecordType": { "Id": "savings-plan" }, "RecordTypeId": "savings-plan", "CA10Z1__disappearanceTime__c": null, "CA10Z1__provisioningState__c": "Succeeded", "CA10Z1__CaAzureSavingsPlanUtilization__r": [ { "Id": "util-below", "RecordType": { "Id": "utilization" }, "RecordTypeId": "utilization", "CA10Z1__disappearanceTime__c": null, "CA10Z1__benefit__c": "below", "CA10Z1__usageDate__c": "2026-09-01", "CA10Z1__avgUtilizationPercentage__c": 79.99 } ] }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "599", "conditionText": "CA10Z1__CaAzureSavingsPlanUtilization__r.has(COMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2026-09-15T00:00:00Z" }, "Id": "boundary", "RecordType": { "Id": "savings-plan" }, "RecordTypeId": "savings-plan", "CA10Z1__disappearanceTime__c": null, "CA10Z1__provisioningState__c": "Succeeded", "CA10Z1__CaAzureSavingsPlanUtilization__r": [ { "Id": "util-stale-missing-average", "RecordType": { "Id": "utilization" }, "RecordTypeId": "utilization", "CA10Z1__disappearanceTime__c": null, "CA10Z1__benefit__c": "boundary", "CA10Z1__usageDate__c": "2026-08-01", "CA10Z1__avgUtilizationPercentage__c": null }, { "Id": "util-gone-low", "RecordType": { "Id": "utilization" }, "RecordTypeId": "utilization", "CA10Z1__disappearanceTime__c": "2026-09-14T00:00:00Z", "CA10Z1__benefit__c": "boundary", "CA10Z1__usageDate__c": "2026-09-01", "CA10Z1__avgUtilizationPercentage__c": 1 }, { "Id": "util-boundary", "RecordType": { "Id": "utilization" }, "RecordTypeId": "utilization", "CA10Z1__disappearanceTime__c": null, "CA10Z1__benefit__c": "boundary", "CA10Z1__usageDate__c": "2026-09-01", "CA10Z1__avgUtilizationPercentage__c": 80 } ] } ] - path: /types/CA10Z1__CaAzureSavingsPlan__c/object.extracts.yaml md5Hash: A48C2F3CC67C2B1D21FA44A52C30DEC9 content: | --- extracts: - name: "CA10Z1__provisioningState__c" value: FIELD: path: "CA10Z1__provisioningState__c" - name: "CA10Z1__expiryDateTime__c" value: FIELD: path: "CA10Z1__expiryDateTime__c" - path: /types/CA10Z1__CaAzureSavingsPlanUtilization__c/object.extracts.yaml md5Hash: 26CE1DEC06D06DADE370978CC555F6EC content: | --- extracts: - name: "CA10Z1__avgUtilizationPercentage__c" value: FIELD: path: "CA10Z1__avgUtilizationPercentage__c" - name: "CA10Z1__usageDate__c" value: FIELD: path: "CA10Z1__usageDate__c" - name: "CA10Z1__benefit__c" value: FIELD: path: "CA10Z1__benefit__c" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "gone", "expectedResult" : { "status" : "DISAPPEARED", "conditionIndex" : "99", "conditionText" : "isDisappeared(CA10Z1__disappearanceTime__c)", "runtimeError" : null } }, { "Id" : "missing-state", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "199", "conditionText" : "extract('CA10Z1__provisioningState__c').isEmpty()", "runtimeError" : null } }, { "Id" : "expired", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "299", "conditionText" : "extract('CA10Z1__provisioningState__c') != 'Succeeded'", "runtimeError" : null } }, { "Id" : "fresh-incomplete", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "399", "conditionText" : "CA10Z1__CaAzureSavingsPlanUtilization__r.has(UNDETERMINED)", "runtimeError" : null } }, { "Id" : "missing-usage-date", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "399", "conditionText" : "CA10Z1__CaAzureSavingsPlanUtilization__r.has(UNDETERMINED)", "runtimeError" : null } }, { "Id" : "stale-incomplete", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "600", "conditionText" : "otherwise", "runtimeError" : null } }, { "Id" : "mixed-recent-periods", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "499", "conditionText" : "CA10Z1__CaAzureSavingsPlanUtilization__r.has(INCOMPLIANT)", "runtimeError" : null } }, { "Id" : "below", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "499", "conditionText" : "CA10Z1__CaAzureSavingsPlanUtilization__r.has(INCOMPLIANT)", "runtimeError" : null } }, { "Id" : "boundary", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "599", "conditionText" : "CA10Z1__CaAzureSavingsPlanUtilization__r.has(COMPLIANT)", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10Z1__CaAzureSavingsPlan__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__disappearanceTime__c" : new Date("2026-09-14T00:00:00Z"), "CA10Z1__provisioningState__c" : "Succeeded", "Id" : "gone", "RecordTypeId" : "savings-plan" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__provisioningState__c" : "", "Id" : "missing-state", "RecordTypeId" : "savings-plan" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__provisioningState__c" : "Expired", "Id" : "expired", "RecordTypeId" : "savings-plan" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__provisioningState__c" : "Succeeded", "Id" : "fresh-incomplete", "RecordTypeId" : "savings-plan" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__provisioningState__c" : "Succeeded", "Id" : "missing-usage-date", "RecordTypeId" : "savings-plan" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__provisioningState__c" : "Succeeded", "Id" : "stale-incomplete", "RecordTypeId" : "savings-plan" }, { "context" : { "snapshotTime" : new Date("2026-09-05T00:00:00Z") }, "CA10Z1__provisioningState__c" : "Succeeded", "Id" : "mixed-recent-periods", "RecordTypeId" : "savings-plan" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__provisioningState__c" : "Succeeded", "Id" : "below", "RecordTypeId" : "savings-plan" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__provisioningState__c" : "Succeeded", "Id" : "boundary", "RecordTypeId" : "savings-plan" } ]; """; CREATE TEMP FUNCTION mock_CA10Z1__CaAzureSavingsPlanUtilization__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__usageDate__c" : new Date("2026-09-01"), "CA10Z1__avgUtilizationPercentage__c" : null, "CA10Z1__benefit__c" : "fresh-incomplete", "Id" : "util-missing-average", "RecordTypeId" : "utilization" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__avgUtilizationPercentage__c" : 50, "CA10Z1__benefit__c" : "missing-usage-date", "Id" : "util-missing-date", "RecordTypeId" : "utilization" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__usageDate__c" : new Date("2026-08-01"), "CA10Z1__avgUtilizationPercentage__c" : null, "CA10Z1__benefit__c" : "boundary", "Id" : "util-stale-missing-average", "RecordTypeId" : "utilization" }, { "context" : { "snapshotTime" : new Date("2026-09-05T00:00:00Z") }, "CA10Z1__usageDate__c" : new Date("2026-08-01"), "CA10Z1__avgUtilizationPercentage__c" : 70, "CA10Z1__benefit__c" : "mixed-recent-periods", "Id" : "util-low", "RecordTypeId" : "utilization" }, { "context" : { "snapshotTime" : new Date("2026-09-05T00:00:00Z") }, "CA10Z1__usageDate__c" : new Date("2026-09-01"), "CA10Z1__avgUtilizationPercentage__c" : 95, "CA10Z1__benefit__c" : "mixed-recent-periods", "Id" : "util-high", "RecordTypeId" : "utilization" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__usageDate__c" : new Date("2026-09-01"), "CA10Z1__avgUtilizationPercentage__c" : 79.99, "CA10Z1__benefit__c" : "below", "Id" : "util-below", "RecordTypeId" : "utilization" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__disappearanceTime__c" : new Date("2026-09-14T00:00:00Z"), "CA10Z1__usageDate__c" : new Date("2026-09-01"), "CA10Z1__avgUtilizationPercentage__c" : 1, "CA10Z1__benefit__c" : "boundary", "Id" : "util-gone-low", "RecordTypeId" : "utilization" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "CA10Z1__usageDate__c" : new Date("2026-09-01"), "CA10Z1__avgUtilizationPercentage__c" : 80, "CA10Z1__benefit__c" : "boundary", "Id" : "util-boundary", "RecordTypeId" : "utilization" } ]; """; CREATE TEMP FUNCTION mock_RecordType() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "Id" : "savings-plan" }, { "context" : { "snapshotTime" : new Date("2026-09-15T00:00:00Z") }, "Id" : "utilization" } ]; """; CREATE TEMP FUNCTION process_CA10Z1__CaAzureSavingsPlan__c( obj STRUCT< CA10Z1__disappearanceTime__c TIMESTAMP, CA10Z1__provisioningState__c STRING, CA10Z1__CaAzureSavingsPlanUtilization__r ARRAY, result STRUCT >>, Id STRING, RecordTypeId STRING, RecordType STRUCT< Id STRING > >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var TextLib = new function () { this.normalize = function(arg) { return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase(); }; this.isEmpty = function(arg) { return this.normalize(arg) == ''; }; this.isNotEmpty = function(arg) { return this.normalize(arg) != ''; }; this.equal = function(left, right) { return this.normalize(left) == this.normalize(right); }; this.notEqual = function(left, right) { return this.normalize(left) != this.normalize(right); }; this.startsWith = function(arg, substring) { return this.normalize(arg).startsWith(this.normalize(substring)); }; this.endsWith = function(arg, substring) { return this.normalize(arg).endsWith(this.normalize(substring)); }; this.contains = function(arg, substring) { return this.normalize(arg).includes(this.normalize(substring)); }; this.containsAll = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.every(sub => normalizedArg.includes(this.normalize(sub))); }; this.containsAny = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.some(sub => normalizedArg.includes(this.normalize(sub))); }; }(); var references1 = []; // condition[0], conditionIndex:[0..99] references1.push('Deleted From Azure [CA10Z1__disappearanceTime__c]: ' + obj.CA10Z1__disappearanceTime__c); if (obj.CA10Z1__disappearanceTime__c != null) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10Z1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[1], conditionIndex:[100..199] function extract3() { if (!this.out) { this.out = obj.CA10Z1__provisioningState__c; } return this.out; }; references1.push('Provisioning State [obj.CA10Z1__provisioningState__c]: ' + obj.CA10Z1__provisioningState__c); if (TextLib.isEmpty(extract3.call(extract3))) { return {status: 'UNDETERMINED', conditionIndex: 199, conditionText: "extract('CA10Z1__provisioningState__c').isEmpty()", currentStateMessage: "The Savings Plan provisioning state is unavailable.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[2], conditionIndex:[200..299] function extract6() { if (!this.out) { this.out = obj.CA10Z1__provisioningState__c; } return this.out; }; if (TextLib.notEqual(extract6.call(extract6), 'Succeeded')) { return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10Z1__provisioningState__c') != 'Succeeded'", currentStateMessage: "The Savings Plan is not successfully provisioned.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } var count_CA10Z1__CaAzureSavingsPlanUtilization__r_UNDETERMINED8 = 0; if (obj.CA10Z1__CaAzureSavingsPlanUtilization__r != null) { for (var i9 = 0; i9 < obj.CA10Z1__CaAzureSavingsPlanUtilization__r.length; i9++) { if (typeof(obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i9].status) !== 'undefined') { if (obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i9].status == 'UNDETERMINED') { count_CA10Z1__CaAzureSavingsPlanUtilization__r_UNDETERMINED8 += obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i9].count; } } else { if (obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i9].result.status == 'UNDETERMINED') { count_CA10Z1__CaAzureSavingsPlanUtilization__r_UNDETERMINED8 += 1; } } } } // condition[3], conditionIndex:[300..399] references1.push('Related list [CA10Z1__CaAzureSavingsPlanUtilization__r] ' + (count_CA10Z1__CaAzureSavingsPlanUtilization__r_UNDETERMINED8 > 0 ? 'has' : 'does not have') + ' objects in UNDETERMINED status'); if (count_CA10Z1__CaAzureSavingsPlanUtilization__r_UNDETERMINED8 > 0) { return {status: 'UNDETERMINED', conditionIndex: 399, conditionText: "CA10Z1__CaAzureSavingsPlanUtilization__r.has(UNDETERMINED)", currentStateMessage: "A utilization record within the last 40 days has incomplete data.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } var count_CA10Z1__CaAzureSavingsPlanUtilization__r_INCOMPLIANT10 = 0; if (obj.CA10Z1__CaAzureSavingsPlanUtilization__r != null) { for (var i11 = 0; i11 < obj.CA10Z1__CaAzureSavingsPlanUtilization__r.length; i11++) { if (typeof(obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i11].status) !== 'undefined') { if (obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i11].status == 'INCOMPLIANT') { count_CA10Z1__CaAzureSavingsPlanUtilization__r_INCOMPLIANT10 += obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i11].count; } } else { if (obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i11].result.status == 'INCOMPLIANT') { count_CA10Z1__CaAzureSavingsPlanUtilization__r_INCOMPLIANT10 += 1; } } } } // condition[4], conditionIndex:[400..499] if (count_CA10Z1__CaAzureSavingsPlanUtilization__r_INCOMPLIANT10 > 0) { return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "CA10Z1__CaAzureSavingsPlanUtilization__r.has(INCOMPLIANT)", currentStateMessage: "Savings Plan utilization was below 80% within the last 40 days.", currentStateReferences: references1.join('\n'), remediation: "Review recent utilization and adjust future Savings Plan commitment coverage if the shortfall is persistent.", runtimeError: null}; } var count_CA10Z1__CaAzureSavingsPlanUtilization__r_COMPLIANT12 = 0; if (obj.CA10Z1__CaAzureSavingsPlanUtilization__r != null) { for (var i13 = 0; i13 < obj.CA10Z1__CaAzureSavingsPlanUtilization__r.length; i13++) { if (typeof(obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i13].status) !== 'undefined') { if (obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i13].status == 'COMPLIANT') { count_CA10Z1__CaAzureSavingsPlanUtilization__r_COMPLIANT12 += obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i13].count; } } else { if (obj.CA10Z1__CaAzureSavingsPlanUtilization__r[i13].result.status == 'COMPLIANT') { count_CA10Z1__CaAzureSavingsPlanUtilization__r_COMPLIANT12 += 1; } } } } // condition[5], conditionIndex:[500..599] if (count_CA10Z1__CaAzureSavingsPlanUtilization__r_COMPLIANT12 > 0) { return {status: 'COMPLIANT', conditionIndex: 599, conditionText: "CA10Z1__CaAzureSavingsPlanUtilization__r.has(COMPLIANT)", currentStateMessage: "Savings Plan utilization met the 80% threshold throughout the available records from the last 40 days.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } return {status: 'UNDETERMINED', conditionIndex: 600, conditionText: "otherwise", currentStateMessage: "No complete Savings Plan utilization record is available within the last 40 days.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; CREATE TEMP FUNCTION process_CA10Z1__CaAzureSavingsPlanUtilization__r( obj STRUCT< CA10Z1__disappearanceTime__c TIMESTAMP, CA10Z1__usageDate__c DATE, CA10Z1__avgUtilizationPercentage__c FLOAT64, CA10Z1__benefit__c STRING, Id STRING, RecordTypeId STRING, RecordType STRUCT< Id STRING > >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var IsEmptyLib = new function () { this.simpleIsEmpty = function(arg) { return arg == null; }; this.simpleIsNotEmpty = function(arg) { return arg != null; }; }(); var todayMinus40Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (-40 * 86400000); var todayPlus1Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (1 * 86400000); var references1 = []; // condition[0], conditionIndex:[0..99] references1.push('Deleted From Azure [CA10Z1__disappearanceTime__c]: ' + obj.CA10Z1__disappearanceTime__c); if (obj.CA10Z1__disappearanceTime__c != null) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10Z1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[1], conditionIndex:[100..199] function extract3() { if (!this.out) { this.out = obj.CA10Z1__usageDate__c; } return this.out; }; references1.push('Usage Date [obj.CA10Z1__usageDate__c]: ' + obj.CA10Z1__usageDate__c); if (IsEmptyLib.simpleIsEmpty(extract3.call(extract3))) { return {status: 'UNDETERMINED', conditionIndex: 199, conditionText: "extract('CA10Z1__usageDate__c').isEmpty()", currentStateMessage: "The utilization record's Usage Date is unavailable.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[2], conditionIndex:[200..299] function extract6() { if (!this.out) { this.out = obj.CA10Z1__usageDate__c; } return this.out; }; if (!(extract6.call(extract6) != null && extract6.call(extract6).getTime() >= todayMinus40Day && extract6.call(extract6).getTime() < todayPlus1Day)) { return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "not(extract('CA10Z1__usageDate__c').withinLastDays(40))", currentStateMessage: "The utilization record is outside the 40-day reporting window.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[3], conditionIndex:[300..399] function extract10() { if (!this.out) { this.out = obj.CA10Z1__avgUtilizationPercentage__c; } return this.out; }; references1.push('Utilization Percentage, Avg [obj.CA10Z1__avgUtilizationPercentage__c]: ' + obj.CA10Z1__avgUtilizationPercentage__c); if (IsEmptyLib.simpleIsEmpty(extract10.call(extract10))) { return {status: 'UNDETERMINED', conditionIndex: 399, conditionText: "extract('CA10Z1__avgUtilizationPercentage__c').isEmpty()", currentStateMessage: "The utilization record's average utilization is unavailable.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[4], conditionIndex:[400..499] function extract14() { if (!this.out) { this.out = obj.CA10Z1__avgUtilizationPercentage__c; } return this.out; }; if (extract14.call(extract14) != null && 80.0 != null && extract14.call(extract14) < 80.0) { return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10Z1__avgUtilizationPercentage__c') < number(80.0)", currentStateMessage: "Average utilization is below 80%.", currentStateReferences: references1.join('\n'), remediation: "Review recent eligible usage and future commitment requirements.", runtimeError: null}; } return {status: 'COMPLIANT', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "Average utilization meets the 80% threshold.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; SELECT expectedResult.Id as Id, IF ( IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '') AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1) AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '') AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''), "MATCH", "FAIL" ) as match, expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus, expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex, expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText, expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError FROM UNNEST(mock_ExpectedResult()) expectedResult LEFT JOIN ( SELECT sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__provisioningState__c AS CA10Z1__provisioningState__c, `CA10Z1__CaAzureSavingsPlanUtilization__r`.arr AS CA10Z1__CaAzureSavingsPlanUtilization__r, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.Id AS Id ) AS RecordType, process_CA10Z1__CaAzureSavingsPlan__c( STRUCT( sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__provisioningState__c AS CA10Z1__provisioningState__c, `CA10Z1__CaAzureSavingsPlanUtilization__r`.arr AS CA10Z1__CaAzureSavingsPlanUtilization__r, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.Id AS Id ) AS RecordType ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10Z1__CaAzureSavingsPlan__c()) AS sObject LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType` ON sObject.RecordTypeId = `RecordType`.Id LEFT JOIN ( SELECT sObject.CA10Z1__benefit__c, ARRAY_AGG( STRUCT( sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__usageDate__c AS CA10Z1__usageDate__c, sObject.CA10Z1__avgUtilizationPercentage__c AS CA10Z1__avgUtilizationPercentage__c, sObject.CA10Z1__benefit__c AS CA10Z1__benefit__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.Id AS Id ) AS RecordType, process_CA10Z1__CaAzureSavingsPlanUtilization__r( STRUCT( sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__usageDate__c AS CA10Z1__usageDate__c, sObject.CA10Z1__avgUtilizationPercentage__c AS CA10Z1__avgUtilizationPercentage__c, sObject.CA10Z1__benefit__c AS CA10Z1__benefit__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, STRUCT ( `RecordType`.Id AS Id ) AS RecordType ), sObject.context.snapshotTime ) as result ) ) AS arr FROM UNNEST(mock_CA10Z1__CaAzureSavingsPlanUtilization__c()) AS sObject LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType` ON sObject.RecordTypeId = `RecordType`.Id GROUP BY sObject.CA10Z1__benefit__c ) AS `CA10Z1__CaAzureSavingsPlanUtilization__r` ON sObject.Id = `CA10Z1__CaAzureSavingsPlanUtilization__r`.CA10Z1__benefit__c ) sObject ON sObject.Id = expectedResult.Id;